Re: bindings and NSNumberFormatter, enforcing min/max values
Re: bindings and NSNumberFormatter, enforcing min/max values
- Subject: Re: bindings and NSNumberFormatter, enforcing min/max values
- From: Martin Wierschin <email@hidden>
- Date: Fri, 17 Sep 2010 12:16:34 -0700
On 2010.09.16, at 7:52 PM, Ken Thomases wrote:
On Sep 16, 2010, at 5:06 PM, Quincey Morris wrote:
Regarding NSUserDefaults, I don't see anything in the documentation
that claims KVC compliance for NSUserDefaults, though I could
easily have missed it.
You're not supposed to bind to the shared NSUserDefaults instance.
There's a separate class, NSUserDefaultController, which was
specifically introduced for KVO and binding. This is what IB offers
as one of the built-in bindings targets (Shared User Defaults
Controller).
So, I suspect the category is on the wrong class.
I am binding to the shared NSUserDefaultsController in IB, not
NSUserDefaults directly. But adding a category to the controller for
individual default properties won't work, because the controller just
passes the validation on to NSUserDefaults (or at least it should).
If everything behaved as I expect, when the controller is asked to
validate the key path "values.mySpecialProperty", the defaults should
in turn be asked to validate the key "mySpecialProperty". The trouble
is that at no point do either of these classes try to dispatch -
validateMySpecialProperty:error: to any instance. In fact,
NSUserDefaults never even receives -validateValue:forKey:error:
I suppose if I was desperate, I could override -
[NSUserDefaultsController validateValue:forKeyPath:error:] parse
"values.propertyName" and handle dispatching validation to
NSUserDefaults myself.
Well, perhaps I'll file a bug / enhancement on this. For now, my
NSNumberFormatter subclass that clips to the min/max is working just
fine, and I don't have any more exotic validation needs.
Thanks,
~Martin
_______________________________________________
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