I have struggled with the setup of KVO for a few hours and I managed to get it to work:
This works:
[self addObserver:self forKeyPath:@"session.loginState" options:0 context:nil];
This doesn't:
[self addObserver:self.session forKeyPath:@"loginState" options:0 context:nil];
Please note that self.session
lazily creates an empty Session
object so self.session is never nil
. However, it seems that:
- the keypath
session.loginState
ofself
is not the same as... - the keypath
loginState
ofself.session
from a KVO perspective
Why is this the case?