I have a MainViewController with NSString property currentTag. So I do:
[self addObserver:self forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];
and this works fine, and the changes do get handled properly. However, I have another class SecondViewController, and I also want it to observe MainViewController's currentTag, so in the SecondViewController's viewDidLoad method, I do:
[self addObserver:self.mainViewController forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];
However, this one doesn't get handled for some reason. It never gets called. I want to make sure my syntax and form is correct before looking elsewhere in my code for the problem. Does this code seem ok?
You're doing it wrong, you should do:
[self.mainViewController addObserver:self forKeyPath:@"currentTag" options:NSKeyValueObservingOptionNew context:nil];