November 2013
Beginner
325 pages
9h 47m
English
What if you want to observe lastTimeString instead of lastTime? Try it. In main.m, start observing lastTimeString:
__unused BNRObserver *observer = [[BNRObserver alloc] init];
[logger addObserver:observer
forKeyPath:@"lastTimeString"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:nil];
If you build and run the program, you will see that the notifications are not being sent properly. The system does not know that lastTimeString changes whenever lastTime changes.
To fix this, you need to tell the system that lastTime affects lastTimeString. This is done by implementing a class method. Open BNRLogger.m and add this class method:
+ (NSSet *)keyPathsForValuesAffectingLastTimeString { ...Read now
Unlock full access