I have seen some guides that say to do this, and others that say setting initial values and keys of NSUserDefaults this way will cause problems when an app is updated. I'm hoping I can definitively answer that here. In my appdelegate didFinishLaunchingWithOptions method I have:
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![defaults integerForKey:@"totalDays"]) {
// if there is no value for the key, set it to 1
[defaults setInteger:0 forKey:@"totalDays"];
}
if (![defaults objectForKey:@"currentDate"]) {
[defaults setObject:@"32 01" forKey:@"currentDate"];
}
if (! [defaults boolForKey:@"marked"]) {
[defaults setBool:NO forKey:@"marked"];
}
if (![defaults arrayForKey:@"checkedrows"]) {
NSMutableArray *arr1 = [NSMutableArray arrayWithArray:[defaults arrayForKey:@"checkedrows"]];
}
[defaults synchronize];