1

In my application delegate I have an NSString which can be modified by a class. What I want to do is to have another class observe this NSString and to react whenever this NSString is changed.

Does anybody know how I can do this?

Paul Peelen
  • 10,073
  • 15
  • 85
  • 168

1 Answers1

3

On the "other class" you must do something like:

[MyAppDelegate addObserver:self forKeyPath:@"VARIABLE_NAME" options:NSKeyValueObservingOptionNew context:nil];

and implement

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context;
Adri
  • 530
  • 2
  • 8