Hi,

I've been playing around with bindings to NSUserDefaultsController in a very simple app to test saving preferences, but the [sharedUserDefaultsController save:self] method seems to return immediately without waiting for the save operation to complete.

The save does actually take place, which I can see if I open the plist file in Property List Editor, but if the very next line after sending the save message is one which reads a property from the plist, it's the old value which gets returned rather than the newly saved one.

My test app consists of only one window with a slider (whose value is bound to the Shared User Defaults Controller), and three buttons: one connected to savePrefs, one to revertPrefs, and one to checkValue which prints out the slider's value as stored within the model.

Here's the entire code:

-(id)init {
        [super init];
[[NSUserDefaultsController sharedUserDefaultsController] setAppliesImmediately:NO];
        myPrefs = [NSUserDefaults standardUserDefaults];
        [self readPrefs];
        return self;
}

-(void) readPrefs{
        //[myPrefs synchronize];  //this line doesn't make any difference
        theValue = [myPrefs objectForKey:@"thevalue"];
}

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

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

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

If I move [self readPrefs] out of the savePrefs method and into checkValue, it prints the new value as expected - but I don't want to be reading the preferences every time I need to use that particular variable. Can someone explain the right way to do this please?

For what it's worth, I also get these compiler warnings for the line with [sharedUserDefaultsController save:]

warning: multiple methods named '-save:' found
warning: using '-(void)save:(id)sender'
warning: also found '-(BOOL)save:(NSError **)error'

Thanks
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