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

Re: Defaults registration


  • Subject: Re: Defaults registration
  • From: Paul Lynch <email@hidden>
  • Date: Tue, 25 Apr 2006 19:36:37 +0100

I don't think that I was recommending using plists to handle defaults, just answering the question with some hints - rather than the, too easy, explicit solution; and that is a difference in style.

However, to answer your question: most of the time I hard code preferences, just like you. I'm working on two apps right now; one of them has hard coded defaults, and the other (Mesa) I just converted to using a plist.

The reason I decided to go with a plist was because it is a single point to change, external to the application, so support staff can more easily read it. Plus I can allow advanced users to edit it, if they really need to for some reason. Editing a plist has its own hazards of course, but it beats editing the code. Plists are reasonable documentation, provided they are old-style.

I got the impression from the OP that the exercise was one of those "QED" types (you know, where the professor writes a problem on the board at the end of a lecture, and scribbles at the bottom: "for extra credit - QED"), and wasn't intended to be obvious without a lot of documentation reading, something which most posters either could do with a lot more of, or a lot less of - depending.


On 25 Apr 2006, at 14:21, Ondra Cada wrote:

Incidentally...

On Apr 25, 2006, at 3:03 PM, Paul Lynch wrote:

Look at NSPropertyListSerialization and NSDictionary dictionaryWithContentsOfFile:, and read Property List Programming Guide for Cocoa - that's how to read a plist; it's not immediately obvious how to hook this in with NSUserDefaults, but it's not exactly hard, either. (Hint given rather than an explicit solution)

Perhaps it is just a difference in programming style, but myself, I've found that registering defaults from a hard-coded "dictionaryWithObjectsAndKeys" is in very vast majority of cases the best course. Registered defaults in plists are neat, but in my experience in 99.99 % of projects, including pretty complex ones, it is not worth the hassle, for this kind of flexibility just is not needed: never ever have I changed the default plists without recompiling the application itself :)


(Still there are cases when this gets handy, e.g., you may want to load the default plists from bundles and register them automagically before *either* the bundle itself gets loaded *or* the prefs panel gets opened, whatever comes first; but I would consider this a pretty advanced technique and would not teach it in Cocoa 101 :))

Is it just me?

_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Newbie questions (From: Xavier Elizalde <email@hidden>)
 >Re: Newbie questions (From: Paul Lynch <email@hidden>)
 >Defaults registration (From: Ondra Cada <email@hidden>)

  • Prev by Date: Re: appicationDidFinishLaunching?
  • Next by Date: Re: Possible bug in NSTextField?
  • Previous by thread: Defaults registration
  • Next by thread: Re: Newbie questions
  • Index(es):
    • Date
    • Thread