views:

160

answers:

1

Hi all,

After a lot of searching I was not able to find wheather you need to pass a dictionary object to:

[NSUserDefaultsDidChangeNotification addObserver: forKeyPath: options: context:];

and what should be provided in options if I want to be notified for even a single change in the userDefaults. Also what is keypath?

Thanx in advance.

+3  A: 

Hi.

NSUserDefaultsDidChangeNotification is just a notification that is sent out when the defaults are changed. To listen out for it you need this code :

    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center addObserver:self
               selector:@selector(defaultsChanged:)  
                   name:NSUserDefaultsDidChangeNotification
                 object:nil];

This will call the method defaultsChanged: when the notification is fired. You need to implement this method like this :

- (void)defaultsChanged:(NSNotificaiton *)notification {
    // Do stuff in here!
}
deanWombourne
Thanx deanWombourne, exactly what I was looking for...
neha