views:

42

answers:

1

Hi,

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?

Best regards,
Paul Peelen

+2  A: 

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
Thanks. That did the trick!
Paul Peelen