Skip to content

Instantly share code, notes, and snippets.

@dnstevenson
Created December 1, 2011 01:24
Show Gist options
  • Save dnstevenson/1412548 to your computer and use it in GitHub Desktop.
Save dnstevenson/1412548 to your computer and use it in GitHub Desktop.
Saving Array
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSFileManager *fileManager = [[NSFileManager alloc] init];
if (![fileManager fileExistsAtPath:documentsDirectory]) {
[fileManager createDirectoryAtPath:documentsDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *dbFilePath = [documentsDirectory stringByAppendingPathComponent:@"high_scores.out"];
NSLog(@"%@", dbFilePath);
NSMutableArray *highScores = [NSMutableArray arrayWithContentsOfFile:dbFilePath];
for (NSString *s in highScores) {
NSLog(@"out: %@", s);
}
[highScores addObject:@"hi"];
if ([highScores writeToFile:dbFilePath atomically:YES]) {
NSLog(@"success saving file");
}
else {
NSLog(@"error saving file");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment