Changeset 151

Show
Ignore:
Timestamp:
04/21/08 11:37:15 (4 weeks ago)
Author:
andym
Message:

Because we use CF calls to update user defaults for the sake of bundles, our synchronize calls don't cause NSUserDefaultsControllers to update. I can't totally fix this for non-app bundles, since there's no way I know of to get an NSUserDefaults object for their defaults, but this patch will fix things for apps.
Thanks to boredzo for reporting the bug.
Fixes #185.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/SUUserDefaults.m

    r105 r151  
    5454        CFPreferencesSetValue((CFStringRef)defaultName, value, (CFStringRef)identifier,  kCFPreferencesCurrentUser,  kCFPreferencesAnyHost); 
    5555        CFPreferencesSynchronize((CFStringRef)identifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); 
     56        // If anything's bound to this through an NSUserDefaultsController, it won't know that anything's changed. 
     57        // We can't get an NSUserDefaults object for anything other than the standard one for the app, so this won't work for bundles. 
     58        // But it's the best we can do: this will make NSUserDefaultsControllers know about the changes that have been made. 
     59        [[NSUserDefaults standardUserDefaults] synchronize]; 
    5660} 
    5761 
     
    7680        CFPreferencesSetValue((CFStringRef)defaultName, (CFBooleanRef)[NSNumber numberWithBool:value], (CFStringRef)identifier,  kCFPreferencesCurrentUser,  kCFPreferencesAnyHost); 
    7781        CFPreferencesSynchronize((CFStringRef)identifier, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); 
     82        // If anything's bound to this through an NSUserDefaultsController, it won't know that anything's changed. 
     83        // We can't get an NSUserDefaults object for anything other than the standard one for the app, so this won't work for bundles. 
     84        // But it's the best we can do: this will make NSUserDefaultsControllers know about the changes that have been made.     
     85        [[NSUserDefaults standardUserDefaults] synchronize]; 
    7886} 
    7987