Reputation: 1106
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?
Upvotes: 86
Views: 40836
Reputation: 194
The (useful) information provided by the other answers didn't cover my particular case, so I'll add to them.
I wanted to find where the NSUserDefaults
values get stored for a system-wide daemon (a LaunchDaemon
), in my case on macOS Sonoma 14.7.1
. After digging a bit through the system, it turns out that the values are stored in a .plist
file located at:
/private/var/root/Library/Preferences/NAME.plist
This applies to both NSUserDefaults.standardUserDefaults
and [[NSUserDefaults alloc] initWithSuiteName:"com.suite.name"]
, where only the
name of the .plist
file differs (it's the bundle id for the standard
case and the specified suite name for initWithSuiteName:
).
Upvotes: 0
Reputation: 6243
(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
Upvotes: 7
Reputation: 31
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.
Upvotes: 1
Reputation: 37093
On Sierra, I found the data here: ~/Library/Application Support/
.
Upvotes: 2
Reputation: 13204
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
Upvotes: 195