ReactiveObjC(前身是ReactiveCocoa或者RAC)是一个Objective-C框架,实现了函数响应式编程模式。
最简单的例子:
// Whe self.userame chages, logs the ew ame to the cosole.//// RACObserve(self, userame) creates a ew RACSigal that seds the curret// value of self.userame, the the ew value wheever it chages.// -subscribeNext: will execute the block wheever the sigal seds a value.[RACObserve(self, userame) subscribeNext:^(NSStrig *ewName) { NSLog(@"%@", ewName);}];K/V通知
// Oly logs ames that starts with "j".//// -filter returs a ew RACSigal that oly seds a ew value whe its block// returs YES.[[RACObserve(self, userame) filter:^(NSStrig *ewName) { retur [ewName hasPrefix:@"j"]; }] subscribeNext:^(NSStrig *ewName) { NSLog(@"%@", ewName); }];
评论