Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reset the NSUserDefaults data in the iPhone simulator?

I've added NSUserDefaults data retrieval to my app, which is pretty nice. But for testing I would like to reset all the data I added to the defaults database, so that everything is in the state when the user launches the app the first time.

I tried to call:

[NSUserDefaults resetStandardUserDefaults]; 

but that doesn't do anything. The defaults are still saved and can be retrieved.

like image 204
Thanks Avatar asked May 22 '09 15:05

Thanks


People also ask

How do you restart an app on iPhone simulator?

For closing (not quit) the running application in Simulator the keyboard shortcut is "shift+command+h".

Where does the iPhone simulator store its data?

type: ~/Library/Application Support/iPhone Simulator.


1 Answers

You want NSUserDefaults removePersistentDomainForName. This will remove all user defaults for the application:

NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier]; [[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain]; 

For more information on the NSUserDefaults class see the Apple docs.

Alternately, if all you are concerned with is data in the iOS Simulator, you can do that via iOS Simulator > Reset Content and Settings.

enter image description here

like image 113
memmons Avatar answered Sep 29 '22 14:09

memmons