Francis
Francis

Reputation: 279

Cocoa PreferencePane User Defaults always stored in com.apple.systempreferences.plist

I'm developing a PreferencePane in Xcode 4.1, and I can't seem to get it to store the preference values in anything other than com.apple.systempreferences.plist.

I have set the Bundle Identifier for my app in the MyApp-Info.plist file, but this does not seem to be getting picked up.

I have searched extensively for an answer, but cannot find any. You can easily replicate the problem as follows:

In XCode:

  1. Create a new PreferencePane project
  2. Add a NSTextField to the .xib
  3. Bind the text field value to Shared User Defaults Controller, with any key name
  4. Build the project
  5. Right-click on the icon under Products and select "Open with External Editor" to install to System Preferences (this user only)

In System Preferences:

  1. Open your pref pane, and type any value in the text box.
  2. See that your preference value is saved in ~/Library/Preferences/com.apple.systempreferences.plist

But why doesn't it create a new plist file with your specified bundle identifier, and store the preference value in there?

Is this a bug in Xcode 4.1 / Mac OS 10.7 ? Any help much appreciated!

Upvotes: 0

Views: 1684

Answers (2)

Rob Keniger
Rob Keniger

Reputation: 46020

You can use NSUserDefaults to access the defaults for your bundle ID:

[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"yourBundleID"];

This will return a dictionary with the preferences for your bundle. You can then use the setPersistentDomain:forName: method of NSUserDefaults to store an updated preferences dictionary.

Upvotes: 3

mipadi
mipadi

Reputation: 410602

Not a bug -- preferences are stored into the plist corresponding to the application, not the bundle. You'll have to use the Core Foundation prefs system to read and write preferences specific to your bundle.

Upvotes: 0

Related Questions