I need to save some simple application settings and choose to use plist.
After searching stackoverflow and other resources I found that the most used pattern is to read and write using a dictionary. So I'm trying to save app configuration data in a plist, but they are not permanently saved.
This is the code implemented for the button "Save configuration" (of course there is a "config.plist" file with a "initialURL" key)
- (IBAction) saveButtonTapped
{
NSString *plistfile = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
NSMutableDictionary *dict =[NSMutableDictionary dictionaryWithContentsOfFile:plistfile];
[dict setValue:initialURL.text forKey:@"initialURL"];
[dict writeToFile:plistfile atomically:YES];
}
After writeToFile:plistfile, the value that was written in the UITextField named initialURL is writen in the right key, and if reload the same key i get the updated value, but if I exit the application and restart it, the value of initialURL is lost.
Why this happens? Is there anything wrong in expecting that "writeToFile" does actually writes to a file (for me a file is permanent storage, if i write to a file data is stored permanently).
Francesco