RAC(二)
RAC常用方法
- (instancetype)flattenMap:(RACStream * (^)(id value))block {}
直接返回订阅的信号
RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
[subscriber sendNext:@"Signal"];
[subscriber sendCompleted];
return nil;
}];
[[signal flattenMap:^RACStream *(id value) {
return [RACReturnSignal return:value];
}] subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
- (instancetype)map:(id (^)(id value))block{}
返回任意类型的对象
[[signal map:^id(id value) {
NSLog(@"%@",value);
return value;
}] subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
-
(RACSignal *)concat:(RACSignal *)signal {}
组合信号
[[signalB concat:signalA] subscribeNext:^(id _Nullable x) {
NSLog(@"result is = %@", x);
}];
只有signalB执行完[subscriber sendCompleted];才会顺序执行signalA -
(RACSignal *)then:(RACSignal * (^)(void))block {}
组合信号
和上面类似 -
(RACSignal *)merge:(RACSignal *)signal {}
返回一个元组
[[signalA merge:signalB] subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
- (RACSignal *)zipWith:(RACSignal *)signal {}
[[signalA zipWith:signalB] subscribeNext:^(id _Nullable x) {
NSLog(@"%@", x);
}];
- (RACSignal *)combineLatest:(id<NSFastEnumeration>)signals reduce:(id (^)())reduceBlock {}
RACSignal *combineSignal = [RACSignal combineLatest:@[_usernameTextField.rac_textSignal, _passwordTextField.rac_textSignal] reduce:^id(NSString *username, NSString *password){
return @(username.length && password.length);
}];
//作为button是否能点击的组合信号
RAC(_loginButton,enabled) = combineSignal;
过滤
filter:
ignore:
take:
distinctUntilChanged
skip: