removePersistentDomainForName not working for NSUserDefaults

nsuserdefaults, xcode

Solution

It seems that `removePersistentDomainForName:` does not work on OS X 10.8. Furthermore, these things are not functional also:

[[NSUserDefaults standardUserDefaults] setPersistentDomain:@{} forName:[NSBundle mainBundle].bundleIdentifier];

[[NSUserDefaults standardUserDefaults] setValuesForKeysWithDictionary:@{}];

To work around the problem, you may set an arbitrary key-value pair to the domain then remove the pair:

[[NSUserDefaults standardUserDefaults] setPersistentDomain:@{@"": @""} forName:[NSBundle mainBundle].bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@""];

NSLog(@"%@", [[NSUserDefaults standardUserDefaults] persistentDomainForName:[NSBundle mainBundle].bundleIdentifier]); // => (null)

Problem

I'm writing an OS X app. I'm trying to clear NSUserDefaults. I'm currently doing: ``` [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]]; ``` But it's not working, i.e. all the key-value pairs are still there when I print the user defaults. I've also tried adding: ``` [[NSUserDefaults standardUserDefaults] synchronize]; ``` still no luck. Can anyone please help? Thanks in advance!

Original source