• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CFPreferences vs. NSUserDefaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFPreferences vs. NSUserDefaults


  • Subject: CFPreferences vs. NSUserDefaults
  • From: Evan Coyne Maloney <email@hidden>
  • Date: Tue, 26 Mar 2002 14:36:01 -0500

Hello,

I'm writing an application that is attempting to manipulate the user preferences in another application (specifically, the Dock). In and of itself, manipulating the preferences of another application is simple enough using NSUserDefaults by extracting the domain-specific information for the other application (by supplying it's bundle identifier as the domain).

I was able to use NSUserDefaults successfully for retrieving the Dock's defaults by specifying "com.apple.dock" as the domain for the defaults. However, a problem arises when manipulating the preferences of another currently running application: specifically, the NSUserDefaults implementation (and, presumably that of CFPreferences as well) caches information and only reads from/writes to the disk when a synchronize is performed. Unfortunately, it doesn't seem possible to force another application to synchronize its preferences using NSUserDefaults or CFPreferences.

Now, I am aware of NSUserDefaults synchronize method, but it seems to synchronize only the preferences of the app that called it, NOT the preferences of ALL domains modified by the application. I am also aware of CFPreferencesAppSynchronize and CFPreferencesSynchronize, neither of which seem to work on other apps (I've only tried it with the Dock, though), either. (They both return YES regardless of what application domain I give it. I tried testing it with "Dock" and "com.apple.dock" as the application name/ID, and they both returned YES but didn't write the updated ".plist" file.)

I've studied the documentation of both NSUserDefaults and CFPreferences extensively (including the most recent ones on Apple's site), but they seem vague in the area of interapplication preference tweaking. I'm assuming it is possible, or there wouldn't be a way to get/set this information from the API of both mechanisms, which there is.

I AM able to get and set the Dock's preferences with NSUserDefaults, but I don't seem to be able to get the Dock to save its defaults to a file using synchronize. As for CFPreferences, none of the calls I've tried seem to work with the Dock.

All of this experiementation led me to the following questions. Any help/advice/flames would be welcome!

1. What do the CFPreferences calls expect the "appName" parameter to be? "appName" implies name (as in "Dock" or "Finder"), but the documentation says "the ID of the application", which implies bundle identifier (as in "com.apple.dock" or "com.apple.finder").

2. Is NSUserDefaults built on top of CFPreferences? I would assume so, but if that's the case, then why can't I retrieve the keys for the Dock's preferences using CFPreferences? It seems that I can only interact with the Dock's preferences though NSUserDefaults. For example, both of the following calls return nil:

CFPreferencesCopyKeyList((CFStringRef) @"com.apple.dock",
kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);

CFPreferencesCopyKeyList((CFStringRef) @"Dock",
kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);

3. Do the CFPreferences calls simply not work for Cocoa apps? Is the Dock a Carbon app or Cocoa app? (I'd assume Cocoa, since the Dock wasn't ported from OS 9.)

4. Can NSUserDefaults' synchronize method be used to interact with other apps? Even while running? Can the equivalent CFPreferences calls? Or does synchronization only work with the app the calls it? If the latter, then WHY does CFPreferences allow me to specify the application?

5. Lastly, what does preference synchronization do, precisely? The documentation implies that it can be used to (1) reload the ".plist" file from disk AND (2) write the preferences BACK to the ".plist" file. What happens if there's a conflict? The app's preferences change internally AND the file changes THEN a synchronize is performed. What happens? Who gets priority? Is there a merge, a la CVS? Or does everything get hosed?

Thank you in advance for any help you can provide!

Evan Coyne Maloney____________________________________________________
The six-legged fire-breathing dog www.brain-terminal.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: CFPreferences vs. NSUserDefaults
      • From: Chris Parker <email@hidden>
    • Re: CFPreferences vs. NSUserDefaults
      • From: Jonathan Feinberg <email@hidden>
  • Prev by Date: Re: Where to start?
  • Next by Date: Re: Focus ring around NSTableView
  • Previous by thread: Info..
  • Next by thread: Re: CFPreferences vs. NSUserDefaults
  • Index(es):
    • Date
    • Thread