• 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
Re: Registering Defaults
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Registering Defaults


  • Subject: Re: Registering Defaults
  • From: email@hidden
  • Date: Wed, 20 Feb 2002 18:23:13 -0800

First, do I have it right that registerDefaults will only write out
those preferences that are not already in the plist? Otherwise, it
looks like the code on p.161 would wipe out existing preferences.

Second, why *doesn't* the code on p. 161 work? When I run it, merely
opening a window, I don't see any RaiseMan.plist showing up in my
preferences. Isn't that what registerDefaults is supposed to do,
create a preferences file if it doesn't exist? (I know I've called
registerDefaults because of the NSLog() statement that follows).

I only get a plist to show up once I've opened up and played with the
Preferences window.

Well, I don't have the book in question, but no, this is not what registerDefaults does. The doc for it says "Adds the contents of dictionary to the registration domain." This concept of domains is very important. You can read more about in "Programming Topic: User Defaults", which is quite clearly written. Among other things, it points out that the registration domain is not persistent (i.e. nothing is written to disk as a result of setting values in it), and it explains the use of registerDefaults:

The registration domain is a set of application-provided defaults that are used unless a user overrides them. For example, the first time you run Project Builder, there isn't an IndexOnOpen value saved in your defaults database. Consequently, Project Builder registers a default value for IndexOnOpen in the NSRegistrationDomain as a "catch all" value. Project Builder can thereafter assume that an NSUserDefaults object always has a value to return for the default, simplifying the use of user defaults.

You set NSRegistrationDomain defaults programmatically with the method registerDefaults.

So typically an app calls registerDefaults at launch time with a dictionary that defines default values for every defaults key that it uses. This allows the app to then assume that every key will return a value (not nil) when queried, simplifying other code. But because of the domain search order, and values actually defined by the user will override the "default default" values provided via registerDefaults:.

Hope this helps...

Ben Haller
Stick Software
_______________________________________________
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.

  • Prev by Date: Re: Registering Defaults
  • Next by Date: Name for '#' glyph.
  • Previous by thread: Re: Registering Defaults
  • Next by thread: Name for '#' glyph.
  • Index(es):
    • Date
    • Thread