Re: NSUserDefaultsController and KVO
Re: NSUserDefaultsController and KVO
- Subject: Re: NSUserDefaultsController and KVO
- From: David Webster <email@hidden>
- Date: Wed, 10 Dec 2003 19:38:48 +0000
On 10 Dec 2003, at 07:28, Scott Anguish wrote:
>
>
On Dec 9, 2003, at 2:31 PM, David Webster wrote:
>
>
> Sorry for posting this twice - I'm new to lists - forgot to edit
>
> subject line
>
>
>
>>> I have a problem getting back a value from NSUserDefaults that I
>
>>> write
>
>>> to from a popup button bound to NSUserDefaultsController. I need to
>
>>> have my preference controller notified when this popup changes as I
>
>>> need to set the state of other widgets based on this popup.
>
>>
>
>> Why not just create a binding in each of the other controls between
>
>> their value and the same key in the Shared User Defaults controller?
>
>>
>
>> That way, you can let the controller architecture do all of the heavy
>
>> lifting.
>
>>
>
>
>
> Because I need to intercept the change notice to do other things
>
> besides just toggling widgets. I tried to keep the original post
>
> simple
>
> to demonstrate the problem.
>
>
>
> My question is still why does the change object appear to be invalid
>
> (see original post)
>
>
>
> - (void) observeValueForKeyPath:(NSString *)keyPath
>
> ofObject:(id)object
>
> change:(NSDictionary *)change context:(void *)context
>
> {
>
> if ([keyPath isEqualToString:@"values.DPMetricImperialState"]) {
>
>
>
> // gets to here OK
>
>
>
> id obj = [change objectForKey:NSKeyValueChangeNewKey];
>
> int tag = [obj intValue];
>
>
>
> // its gone into the ether by here but it is the objectForKey:
>
> where I am sure it fails
>
> }
>
>
It's possible that the defaults controller doesn't actually provide a
>
new value.. was it registered for it?
>
>
>
>
> I know I can get the value by doing the following
>
>
>
> int tag = [[[[NSUserDefaultsController sharedUserDefaultsController]
>
> defaults] objectForKey:@"DPMetricImperialState"] intValue];
>
>
>
> and that works but as I am passed the change object by the above
>
> method
>
> - why can't I use it?. Is it a bug?
>
>
>
>
could be.
>
>
Yes, in the original post I showed the following registration:
[defaultsController addObserver:self
forKeyPath:@"values.DPMetricImperialState"
options:NSKeyValueObservingOptionNew context:NULL];
this is just how the docs say to do it. Iterating over the "change"
dictionary (allKeys:) returns two <key> entries - the key of one of
them is NSKeyValueObservingOptionNew (i.e. "new") - its the value that
seems to be corrupt.
David
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.