title: iOS NSUserDefaults Watching the change of values for a single key
body: <p>I have the following code aiming to catch the event of a NSUserDefaults value changing for a particular key. </p>
  
  <pre><code> [[NSUserDefaults standardUserDefaults] addObserver:self
                                      forKeyPath:SOME_NSSTRING_VARIABLE
                                         options:NSKeyValueObservingOptionNew
                                         context:NULL];
  
   - (void)observeValueForKeyPath:(NSString *) keyPath ofObject:(id) object change:(NSDictionary *) change context:(void *) context
  {NSLog (@"Changed for key %@", keyPath); }
  </code></pre>
  
  <p>But the observeValueForKeyPath is never getting called. I even tried replacing the SOME_NSSTRING_VARIABLE too with a string as mentioned in <a href="https://stackoverflow.com/questions/3633973/observing-value-changes-to-an-nsuserdefaults-key">Observing value changes to an NSUserDefaults key</a> but it has not helped.</p>
  
  <p>Update:
  I am changing the NSUserDefaults from a tabview. The above code to monitor changes is in a different tab of the same tabviewcontroller. In the tab where I monitor for the changes (the tab where above code exists), if I add a :</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated
  {
  [super viewWillAppear:animated];
  //   NSLog(@"viewillappear");
  NSUserDefaults *FUDefaults = [NSUserDefaults standardUserDefaults];
  NSLog(@"The username obtained is: %@", [FUDefaults objectForKey:SOME_NSSTRING_VARIABLE]);
  }
  </code></pre>
  
  <p>the updated NSUserDefaults value is obtained correctly, but the observeValueForKeyPath was never called.</p>