Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear UserDefaults for Xcode build of Mac app?

I'm trying to make sure my first-run code works properly, and so I'd like to clear the preferences file created by UserDefaults.standard.set calls. Where is it located, or is there at least a way to clear it out (other than writing it into my app)?

Running Product > Clean does not clear out the defaults.

I've looked in DerivedData, ~/Library/Preferences, /Library/Preferences, and haven't found what I'm looking for.

like image 604
Joshua Breeden Avatar asked Apr 02 '18 07:04

Joshua Breeden


People also ask

How do I remove UserDefaults?

To remove a key-value pair from the user's defaults database, you need to invoke removeObject(forKey:) on the UserDefaults instance. Let's update the previous example. The output in the console confirms that the removeObject(forKey:) method works as advertised.

Where are user defaults stored Macos?

Navigate to AppData -> Library -> Preferences. The property list file (. plist) in this folder is the database file of the standard UserDefaults of your app.

What is Userdefault in Swift?

An interface to the user's defaults database, where you store key-value pairs persistently across launches of your app.


Video Answer


2 Answers

You can use defaults command In Terminal

$ defaults delete com.bundle.identifier

Also you can delete any value in defaults by key, if you don't want to delete whole application defaults plist.

$ defaults delete com.bundle.identifier kSomeKey
like image 70
Andrew Vergunov Avatar answered Nov 02 '22 17:11

Andrew Vergunov


If the app is sandboxed the preferences are located in

~/Library/Containers/[bundle-identifier]/Data/Library/Preferences

If it's not sandboxed the preferences are at the usual location

~/Library/Preferences
like image 28
vadian Avatar answered Nov 02 '22 17:11

vadian