Re: Mysterious NULL Coming From NSUserDefaults
Re: Mysterious NULL Coming From NSUserDefaults
- Subject: Re: Mysterious NULL Coming From NSUserDefaults
- From: "Boaz Stuller" <email@hidden>
- Date: Mon, 7 Jul 2008 01:52:31 -0400
Well, I see a couple problems here
1) Even though you're getting directly passed a color in your setters,
you're ignoring that and trying to find out the color from the wells. That's
bad form for many reasons, and if those backGroundWell and lineWell
variables weren't hooked up correctly, that would explain your symptoms.
Especially since your lineWell and backGroundWell aren't getting hooked up
correctly.
2) Since I can't see your whole project, I can't be 100% sure, but I'm 99%
sure your lineWell and backGroundWell probably aren't getting hooked up
correctly. This is because you named your color setters and getters *the
exact same thing* as the instance variables for your color wells. This is a
big mistake, for reasons that are way too complicated to explain in an
email. The short version is that when nibs are loaded, outlets are set
using key-value coding. If you have a method named -setLineWell: and an
ivar named lineWell, the KVC routines assume that the -setLineWell: method
is the way to set the lineWell ivar and call that method instead of setting
lineWell directly. You can avoid this problem in the future by making your
getter and setter names describe what you're actually getting and setting,
i.e -lineWell and -setLineWell: should get/set an NSColorWell, while
-lineColor and -setLineColor: should get/set an NSColor.
3) Pulling back a bit, you're working way too hard. You don't have to write
any code at all to hook a color well up to a preference key. You just bind
to the 'Shared User Defaults Controller', set the controller key to
'values', the Model Key to whatever you want your preference key to be, and
the Value Transformer to "NSUnarchiveFromData" (it'll be in the popup
menu). It will handle all that archiving and unarchiving you're currently
doing manually.
4) The G in Background should not be capitalized. ;)
Best wishes,
Bo
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden