似乎在 OS X 10.8 上removePersistentDomainForName:
不起作用。此外,这些东西也不起作用:
[[NSUserDefaults standardUserDefaults] setPersistentDomain:@{} forName:[NSBundle mainBundle].bundleIdentifier];
[[NSUserDefaults standardUserDefaults] setValuesForKeysWithDictionary:@{}];
要解决此问题,您可以为域设置任意键值对,然后删除该对:
[[NSUserDefaults standardUserDefaults] setPersistentDomain:@{@"": @""} forName:[NSBundle mainBundle].bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@""];
NSLog(@"%@", [[NSUserDefaults standardUserDefaults] persistentDomainForName:[NSBundle mainBundle].bundleIdentifier]); // => (null)