If the plist is an existing plist included with your app, it is put into a directory that you cannot write to. So you will have to write code to read the data and rewrite it to a different file in a different directory. Once that is done once, then you should read and write from that new writable file.
There are lots of tutorials out there with the exact code you can check out
But here is my code all in my App Delegate. kDataFile is the name of my writable file
Code:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *filePath = [NSString stringWithFormat:@"%@/%@.%@", [self getFilePath], kDataFileName, @".plist"];
if (![fileManager fileExistsAtPath:filePath]) {
NSBundle *bundle = [NSBundle mainBundle];
filePath = [bundle pathForResource:kDataFileName ofType:@"plist"];
}
self.dataInPList = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
...
}
Code:
- (void)applicationWillTerminate:(UIApplication *)application {
// Save data if appropriate
NSString *filePath = [NSString stringWithFormat:@"%@/%@.%@", [self getFilePath], kDataFileName, @".plist"];
[dataInPList writeToFile:filePath atomically:YES];
}
- (NSString *)getFilePath {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;
}
Mark