• 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
NSUserDefaultsController and KVO
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSUserDefaultsController and KVO


  • Subject: NSUserDefaultsController and KVO
  • From: David Webster <email@hidden>
  • Date: Mon, 8 Dec 2003 22:03:48 +0000

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.

The valueSelection is selectedTag
the binding set to - Shared User Defaults,
the controller key to - values and
the Model Key Path to - DPMetricImperialState

It correctly writes to NSUserDefaults (checked it in my
~\Library\Preferences\myapp.plist - it is an NSNumber with the correct
values). I have added the following to observe changes

[defaultsController addObserver:self
forKeyPath:@"values.DPMetricImperialState"

options:NSKeyValueObservingOptionNew
context:NULL];

When I change the popup - the following is called as expected

- (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

............
}
}

Any ideas what I am doing wrong? Thanks.

David Webster
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSUserDefaultsController and KVO
      • From: Chris Hanson <email@hidden>
  • Prev by Date: Re: NSDocument with documents being folders
  • Next by Date: Re: .webloc files and Safari (newbie)
  • Previous by thread: Re: NSDocument with documents being folders
  • Next by thread: Re: NSUserDefaultsController and KVO
  • Index(es):
    • Date
    • Thread