Joshua Breeden
Joshua Breeden

Reputation: 1994

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.

Upvotes: 22

Views: 7206

Answers (2)

AVerguno
AVerguno

Reputation: 1377

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

Upvotes: 22

vadian
vadian

Reputation: 285082

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

Upvotes: 22

Related Questions