0

I have a property list in my application and I have it change the values of all the different fields but when the app is closed all the settings are removed. Here is the code I'm using:

NSBundle *mainBundle = [NSBundle mainBundle];
    NSString *path = [mainBundle pathForResource:@"Settings" ofType:@"plist"];
    //NSNumber *str = [dict objectForKey:@"Auto_Save"];
    NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
        [data setObject:[NSNumber numberWithBool:sender.on] forKey:@"Auto_Save"];
        [data writeToFile:path atomically:YES];

Destiny Dawn
  • 1,457
  • 3
  • 15
  • 29

1 Answers1

0

You can't write back to a file stored in the application bundle. You need to write it to 'disk'.

TomSwift
  • 39,369
  • 12
  • 121
  • 149
  • Just get a path to your documents folder (or Library folder, or whatever) and write the file there. http://stackoverflow.com/questions/5619719/write-a-file-on-ios – TomSwift Sep 12 '12 at 22:40
  • So I need to recreate the file? – Destiny Dawn Sep 12 '12 at 22:42
  • Yes; you can't write to the application bundle - it is read-only, which is what you're attempting to do in your code sample. – TomSwift Sep 12 '12 at 23:04
  • I tried doing what they did in the link you sent me but that didn't work; when I debug it and have it return the value changed it does change it just doesn't save. Is it possible that I could just cache the file? – Destiny Dawn Sep 12 '12 at 23:05