15

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.

Joshua Breeden
  • 1,844
  • 1
  • 16
  • 29

2 Answers2

16

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
vadian
  • 274,689
  • 30
  • 353
  • 361
  • 1
    Not sure if this is a Big Sur change, but I found that I had to additionally kill the `cfprefsd` process after deleting the property list. The alternative would be to use Andrew's approach, but this doesn't seem to remove the property list, rather, it empties it. – Samuel-IH Dec 23 '20 at 20:49
  • For a MacOS app running under Catalina, preferences are in a hidden Library/Preferences folder in User home folder named [bundle-identifier].plist. However, renaming this file does not prevent the application from using values are in it. It seems as though the preferences values are cached and persist even when the user logs out and in again. Restarting clears it. Does killing `cprefsd` have the same effect as restarting? – SimonKravis May 12 '21 at 23:03
16

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
AVerguno
  • 1,277
  • 11
  • 27