Re: Problem with NSUserDefaultsController
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