Created
December 1, 2011 01:24
-
-
Save dnstevenson/1412548 to your computer and use it in GitHub Desktop.
Saving Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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