ReactiveObjC(前身是ReactiveCocoa或者RAC)是一个Objective-C框架,实现了函数响应式编程模式。
最简单的例子:
// When self.username changes, logs the new name to the console.//// RACObserve(self, username) creates a new RACSignal that sends the current// value of self.username, then the new value whenever it changes.// -subscribeNext: will execute the block whenever the signal sends a value.[RACObserve(self, username) subscribeNext:^(NSString *newName) { NSLog(@"%@", newName);}];K/V通知
// Only logs names that starts with "j".//// -filter returns a new RACSignal that only sends a new value when its block// returns YES.[[RACObserve(self, username) filter:^(NSString *newName) { return [newName hasPrefix:@"j"]; }] subscribeNext:^(NSString *newName) { NSLog(@"%@", newName); }];
评论