Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is a Mac Application's NSUserDefaults Data Stored?

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?

like image 500
ahmadbaig Avatar asked Nov 02 '11 15:11

ahmadbaig


People also ask

Where is NSUserDefaults stored?

All the contents saved by NSUserDefaults is saved inside a plist file that can be found under Library -> Preferences -> $AppBundleId.

What types can you store natively in NSUserDefaults?

Types stored in NSUserDefaultsplist type can be stored by NSUserDefaults . These types are NSString(String) , NSArray(Array) , NSDictionary(Dictionary) (for both NSArray and NSDictionary types their contents must be property list objects), NSNumber(Int, Float, Double, Boolean) , NSDate and NSData .

How do you save NSUserDefaults in Objective C?

static func setObject(value:AnyObject ,key:String) { let pref = NSUserDefaults. standardUserDefaults() pref. setObject(value, forKey: key) pref. synchronize() } static func getObject(key:String) -> AnyObject { let pref = NSUserDefaults.

What is NSUserDefaults?

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user's preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed.


1 Answers

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 
like image 136
erkanyildiz Avatar answered Sep 19 '22 07:09

erkanyildiz