• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSUserDefaultsController and KVO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

References: 
 >Re: NSUserDefaultsController and KVO (From: David Webster <email@hidden>)

  • Prev by Date: AuthorizationExecuteWithPrivileges leaving zombie processes! Help?
  • Next by Date: Using Set-user-id bit for CVS directories
  • Previous by thread: Re: NSUserDefaultsController and KVO
  • Next by thread: NSSearchField in toolbars - toolbar won't customize
  • Index(es):
    • Date
    • Thread