iOS监听NSUserDefaults值

有时候需要监听NSUserDefaults值时时变化!发现这个方法挺方便记录一下

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

- (void)defaultsChanged:(NSNotification *)notification { // Get the user defaults NSUserDefaults *defaults = (NSUserDefaults *)[notification object]; // Do something with it NSLog(@"%@", [defaults objectForKey:@"nameOfThingIAmInterestedIn"]);}

地址:http://stackoverflow.com/questions/3166563/how-to-receive-nsuserdefaultsdidchangenotification-iphone

你可能感兴趣的:(iOS监听NSUserDefaults值)