When i try this code:
if ([[NSFileManager defaultManager] fileExistsAtPath:@"~/Library/Application Support/Staying Afloat/stats/static-stats.plist"] == NO) {
NSMutableDictionary* tempDict = [[NSMutableDictionary alloc]initWithObjectsAndKeys:
[[NSString alloc] initWithString:@"0"],@"completedGames",
[[NSString alloc] initWithString:@"0"],@"floatsCollected",
[[NSString alloc] initWithString:@"0"],@"sec",
[[NSString alloc] initWithString:@"0"],@"subScore",
[[NSString alloc] initWithString:@"0"],@"highScore",
[[NSString alloc] initWithString:@"0"],@"longestSec", nil];
[tempDict writeToFile:@"~/Library/Application Support/Staying Afloat/stats/static-stats.plist" atomically:YES];
NSLog(@"written file");
}
and this outputs with
2012-04-14 19:15:10.009 Staying Afloat[3227:9c07] written file
so the loop has run, but the file isn’t written?
can anyone point my in the right dirrection for saving plists to non-localized places?
EDIT: this is for mac
You need to expand your path using
-(NSString *)stringByExpandingTildeInPathwhen you write and check if the file exist.Edit: Read the method
writeToFile:automaticallyin the NSDictionary documentation. It saysSo just do something like