• 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: Problem with NSUserDefaultsController
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with NSUserDefaultsController


  • Subject: Re: Problem with NSUserDefaultsController
  • From: Mark Allan <email@hidden>
  • Date: Tue, 2 Sep 2008 09:37:04 +0100

I think I've fixed the the problem, thanks to an idea I had whilst reading Oleg's "Bindings - newbie question" thread.

I've added a message within -init to bind my model's variable (theValue) to the appropriate value (thevalue) within the standardUserDefaults dictionary (myPrefs).  Apologies for the similarities in naming the variable and the key - I know it can make readability hard for others, but it's how my mind works unfortunately!

[self bind:@"theValue" toObject:myPrefs withKeyPath:@"thevalue" options:nil];

For completeness, here's the full code which *appears* to work:

-(id)init {
	if(self = [super init]){
		shared = [NSUserDefaultsController sharedUserDefaultsController];
		[shared setAppliesImmediately:NO];
		myPrefs = [NSUserDefaults standardUserDefaults];
		[self bind:@"theValue" toObject:myPrefs withKeyPath:@"thevalue" options:nil];
	}
	return self;
}

-(void) savePrefs:(NSObject *) sender{
	// save prefs and close the window
	[shared save:self];
}

-(void) checkValue:(NSObject *) sender{
	NSLog(@"value is %@",theValue);
}

-(void) revertPrefs:(NSObject *) sender{
	// revert and close the window
	[[NSUserDefaultsController sharedUserDefaultsController] revert:sender];
}


For what it's worth, the [sharedUserDefaultsController save:] message is still returning before performing the save, so if I send any other messages within my savePrefs method, userDefaults will still contain the old value - I'm beginning to wonder if this is a bug within NSUserDefaultsController.

This may not be the right way to do it, but for my purposes, I think it's probably OK.

Mark
_______________________________________________

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

  • Follow-Ups:
    • Re: Problem with NSUserDefaultsController
      • From: Keary Suska <email@hidden>
References: 
 >Re: Problem with NSUserDefaultsController (From: Keary Suska <email@hidden>)
 >Re: Problem with NSUserDefaultsController (From: Mark Allan <email@hidden>)

  • Prev by Date: Re: Creating movie on background thread
  • Next by Date: Re: acceptsFirstMouse with NSTableView
  • Previous by thread: Re: Problem with NSUserDefaultsController
  • Next by thread: Re: Problem with NSUserDefaultsController
  • Index(es):
    • Date
    • Thread