Re: Binding to NSUserDefaults
Re: Binding to NSUserDefaults
- Subject: Re: Binding to NSUserDefaults
- From: Ken Thomases <email@hidden>
- Date: Sun, 17 Mar 2013 18:17:45 -0500
On Mar 17, 2013, at 6:00 PM, Seth Willits wrote:
> On Mar 17, 2013, at 11:31 AM, Ken Thomases wrote:
>
>>> In nibs we bind to NSUserDefaults through NSUserDefaultsController, but is there any point in using NSUserDefaultsController when binding to a default through code? (Or using KVO, also.) It's always seemed to work monitoring NSUserDefaults directly.
>>
>> Yes, you should bind through NSUserDefaultsController, regardless. Bindings established in IB are not significantly different from bindings established in code.
>>
>> NSUserDefaults is not KVO-compliant. It may work to fetch the value on a one-time basis (i.e. KVC), but you're not guaranteed to be informed when a default changes.
>
> Question is, when does it not work?
The answer is always: at the worst possible moment. It's unpredictable because it's not guaranteed to work (nor is it guaranteed not to work). In general no property of a Cocoa class can be relied upon to be KVO-compliant unless it is documented to be so.
It might behave differently on different versions of the OS, or different machines.
> I've yet to see it fail.
Why rely on empiricism when the documentation establishes that NSUDC is what you should use?
Regards,
Ken
_______________________________________________
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