I use the NSUserDefaults method to save data. I save an int and an NSMutableArray.
The int gets saved properly when the app terminates, enters the background, or switches to another view. The array saves when the app enters the background and when it switches to another view, but doesn't save every time I exit the simulator and come back in, even though I use the exact same code for the int and the NSMutableArray.
Here's my code for defining the NSMutableArray:
array = [[NSMutableArray alloc] init];
if ([prefs objectForKey:@"array"] != nil) {
array = [prefs objectForKey:@"array"];
}
And then for editing and saving it:
[array addObject:anObject];
[prefs setObject:array forKey:@"array"];
[prefs synchronize];
The int has the exact same code except for the changes between array and int parts.
Can anyone tell me what's wrong? I've checked many related questions but none of them solved my problem.
Thanks in advance.