I’m having problems reading and writing to a plist file. I can read the data OK, but I cant write it.. also, I think I have a memory management issues relating to this. Here’s my code:
+(NSString *) getSettingString: (NSString *)key
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"FSSettings.plist"];
NSMutableDictionary* plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];
NSString *value = [plistDictionary objectForKey:key];
[path release];
return value;
}
+(void) setSettingString: (NSString *)key value:(NSString *)value
{
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"FSSettings.plist"];
NSMutableDictionary* plistDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:finalPath];
[plistDictionary setObject:value forKey:key];
[plistDictionary writeToFile:finalPath atomically:YES];
[path release];
}
You’re trying to write the plist back into your application bundle, which is not allowed. You need to write the file into the documents directory. Details on how to locate this directory can be found here:
http://developer.apple.com/iphone/library/documentation/iphone/conceptual/iphoneosprogrammingguide/StandardBehaviors/StandardBehaviors.html#//apple_ref/doc/uid/TP40007072-CH4-SW11