KVO addObserver:forKeyPath not working

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

Soon after I posted this question, I found out why. The window property is not set yet when view is loaded.

Now comes a new question - what is the correct time/place to add the addObserver method?

KVO addObserver:forKeyPath not working
 
 
Q