Clearing NSUserDefaults

There are many ways to store data in an iOS app. Core Data, SQLite and UIDocuments are all available but often the quick and easy way to store some data is to use NSUserDefaults. Sometimes we need to clear all of NSUserDefaults data in your app. And there are two ways to clear it.

1.Delete all keys from NSUserDefaults dictionary.

[css] – (void)resetDefaults { NSUserDefaults * defs = [NSUserDefaults standardUserDefaults]; NSDictionary * dict = [defs dictionaryRepresentation]; for (id key in dict) { [defs removeObjectForKey:key]; } [defs synchronize]; } [/css]

2.Use NSUserDefaults removePersistentDomainForName method.

[css] NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; [/css] You can try both of them.


[do_widget “Facebook Comments Master”]