I’m implementing saved data on my app by using NSUserDefaults, like this:
[[NSUserDefaults standardUserDefaults] registerDefaults:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:0],@'mySetting',nil]]; // check int firstLaunch = [[NSUserDefaults standardUserDefaults] integerForKey:@'mySetting']; // set [[NSUserDefaults standardUserDefaults] setInteger:1 forKey:@'mySetting'];
Now for development purposes, I’d like to be able to remove the saved data and go back to the defaults, without having to remove the app and re-install it each single time. Is there a quick way to do that? I thought resetStandardUserDefaults would do the job, but it doesn’t.
For the key which you wish to revert to the default,
-removeObjectForKey:will remove its definition from the app preferences. All things being equal, this means that subsequent invocations of-<type>ForKey:will return the registered default.