Hi. I'm trying to read and save to Info.plist. I'm having no problem reading the file... and it would appear that I'm having no problem saving the file after editing one of its values. But when I relaunch the program, the key that I edited, "savedLevelNumber," reverts back to its original value. Here's my code:
I'd greatly appreciate if anyone can help! Thanks!
Code:
// read plist
NSData *plistData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]];
NSString *readError;
NSPropertyListFormat format;
id plist = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListMutableContainers format:&format errorDescription:&readError];
if (!plist) {
NSLog(readError);
[readError release];
} else {
int levelNumber = [[note object] intValue];
[plist setValue:[NSString stringWithFormat:@"%i", levelNumber] forKey:@"savedLevelNumber"];
}
// save plist
NSString *path = [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];
NSData *xmlData;
NSString *saveError;
xmlData = [NSPropertyListSerialization dataFromPropertyList:plist format:NSPropertyListXMLFormat_v1_0 errorDescription:&saveError];
if (xmlData) {
NSLog(@"No error creating XML data.");
[xmlData writeToFile:path atomically:YES];
} else {
NSLog(saveError);
[saveError release];
}
I'd greatly appreciate if anyone can help! Thanks!