Skip to content

Instantly share code, notes, and snippets.

@genemyers
Created October 13, 2018 22:52
Show Gist options
  • Select an option

  • Save genemyers/5fd8de5e7339ac23d6421ea1076cd0eb to your computer and use it in GitHub Desktop.

Select an option

Save genemyers/5fd8de5e7339ac23d6421ea1076cd0eb to your computer and use it in GitHub Desktop.
// Get the URL for the document directory
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSURL *documentDirectoryURL = [[fileManager URLsForDocumentDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0];
// Turn the filename into a string safe for use in a URL
NSString *safeString = [@"scores.plist" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// Create an array for the score
NSMutableArray *array = [[NSMutableArray alloc] init];
[array addObject:[NSNumber numberWithInt:score]];
// Write this array to a URL
NSURL *arrayURL = [NSURL URLWithString:safeString relativeToURL:documentDirectoryURL];
[array writeToURL:arrayURL atomically:YES];
@genemyers
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment