Stalker 受 KVOController 极大启发,为开发者提供了一个友好且基于块的接口,用于 KVO 和 NSNotification
。
//import the header
#import "NSObject+Stalker.h"
// observe the property 'count' for the object spoons
[self.stalker whenPath:@"count"
changeForObject:spoons
options:NSKeyValueObservingOptionNew
then:^(id object, NSDictionary *change) {
}];
// listen to the notification UIApplicationDidBecomeActiveNotification
[self.stalker when:UIApplicationDidBecomeActiveNotification
then:^(NSNotification *notification) {
}];
请注意
STStalker
的实例,它已经通过 NSObject+Stalker
分类提供。Luca Querella [email protected]