81

I am using NSUserDefaults to store some data in my application.

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
[prefs setObject:@"dummy string" forKey:@"lastValue"];
[prefs synchronize];

For testing purposes I need to see the System Preferences plist file where my NSUserDefaults data is saving on the Mac.

I know where the iOS application user defaults are stored, but I don't know about mac application. Where is a Mac Application's NSUserDefaults Data Stored?

Sam Spencer
  • 8,492
  • 12
  • 76
  • 133
ahmadbaig
  • 1,056
  • 1
  • 8
  • 9

5 Answers5

188

They can be found in more than one place:

~/Library/Preferences/com.example.myapp.plist
~/Library/SyncedPreferences/com.example.myapp.plist

and if sandboxed

~/Library/Containers/com.example.myapp/Data/Library/Preferences/com.example.myapp.plist
~/Library/Containers/com.example.myapp/Data/Library/SyncedPreferences/com.example.myapp.plist
erkanyildiz
  • 13,044
  • 6
  • 50
  • 73
  • 16
    These Plists should never be read or edited directly. They are not necessarily what the `NSUserDefaults` class reads or writes to. Instead, always use `defaults read` and `defaults write` in your terminal. Full explanation at the bottom of this thread: https://devforums.apple.com/message/894120 – T Blank Oct 24 '14 at 23:54
  • What about for a screensaver? – Juanjo Conti Jan 23 '15 at 19:55
  • I read @TravisB's warning too late and deleted my app's plist file. I was able to restart my computer and rebuild my app to get the file back. – VinceFior Aug 01 '15 at 04:21
  • @JuanjoConti The "Flurry" screen saver has them in `~/Library/Preferences/ByHost/com.apple.Flurry..plist` – Klaas Jun 27 '16 at 16:36
  • To add to @TBlank's answer, if you're trying to just delete an application's user defaults, you shouldn't do it via deleting the plist file itself - my own testing has shown that the elements will remain cached. To delete, follow the advice in http://superuser.com/questions/907798/deleting-user-defaults-under-mac-os-x-10-10-3/907899#907899 – Vivek Gani Sep 19 '16 at 20:55
  • hmm - my app is sandboxed -but my NSUserdefaults are not appearing in the containers folder. Do I need to change a setting when saving them? – UKDataGeek Jan 27 '17 at 10:38
  • What happens to that data when the user deletes the app? – OrangePot Dec 05 '18 at 17:56
  • @OrangePot It is cached and still there if you install the app again, before you restart macOS. Cache is cleared after restarting macOS. And if you install the app again after macOS restart, only then you get a clear user defaults for the app. – erkanyildiz Jan 14 '19 at 04:14
20

In ~/Library/Preferences/com.example.myapp.plist.

  • 7
    @ahmadbaig: this is no longer completely accurate with the advent of sandboxing, you should change the accept answer to erkanyildiz's – houbysoft Oct 18 '12 at 23:15
7

(Xcode 7.3.1,macOS 10.11.6)

For Additional, if you are using App Groups

if let prefs = NSUserDefaults(suiteName: "group.groupApps")  {
    ...
}

plist file will be here:

~/Library/Group Containers/group.groupApps/Library/Preferences/group.groupApps.plist
hstdt
  • 5,652
  • 2
  • 34
  • 34
2

On Sierra, I found the data here: ~/Library/Application Support/.

funroll
  • 35,925
  • 7
  • 54
  • 59
1

One more possible location for these data comes into play when trying things out in a Playground. I was experimenting with UserDefaults in a Playground, using XCode 8.3 and Swift 3, and wanted to see the resulting plist file. After some detective work (UserDefaults files have the bundle identifier in the filename and calling Bundle.main.bundleIdentifier in a Playground gives the XCode identifier) I found to my great surprise that the UserDefaults data was added to:

~/Library/Preferences/com.apple.dt.Xcode

In other words, keys and values are added to the XCode preferences file! I double-checked by coming up with very unlikely strings for the keys and they were indeed added there. I did not have the courage to try using some keys that were already in use by XCode but caution seems good here.