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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to