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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to