Reputation: 1318
I tried using -resetStandardUserDefaults, I tried removing the plist file, none of those really do what I need. I want to reset my preferences completely, as if the app re-installed. Is there a good solution to this?
I tried :
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
But Xcode complains. Apparently, it doesn't like that the plist file has disappeared. This is Xcode's error :
Upvotes: 1
Views: 1945
Reputation: 53950
You can ask NSUserDefaults
for all the available keys, and loop in order to removes them:
NSDictionary * allObjects;
NSString * key;
allObjects = [ [ NSUserDefaults standardUserDefaults ] dictionaryRepresentation ];
for( key in allObjects )
{
[ [ NSUserDefaults standardUserDefaults ] removeObjectForKey: key ];
}
[ [ NSUserDefaults standardUserDefaults ] synchronize ];
Upvotes: 6