This is the first time I use KVO pattern. The code is quite simple but I could not get it working - the log method never gets run. What's wrong with my code?
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self.view.window addObserver:self
forKeyPath:@"firstResponder"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:nil];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary<NSKeyValueChangeKey,id> *)change
context:(void *)context
{
NSLog(@"%@", change);
}
@end