监听多个信号,处理结果
场景1:界面有多个网络请求,当所有网络请求都完成时,才能展示界面。
- (void)viewDidLoad {
[super viewDidLoad];
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
// requestA()
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[NSThread sleepForTimeInterval:3.0];
[subscriber sendNext:@"网络A加载完成"];
});
return [RACDisposable disposableWithBlock:^{
NSLog(@"取消A信号");
}];
}];
RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
// requestB()
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[NSThread sleepForTimeInterval:5.0];
[subscriber sendNext:@"网络B加载完成"];
});
return [RACDisposable disposableWithBlock:^{
NSLog(@"取消B信号");
}];
}];
[self rac_liftSelector:@selector(responseA:B:) withSignalsFromArray:@[signalA, signalB]];
}
- (void)responseA:(id)a B:(id)b {
NSLog(@"%@, %@", a, b);
}
做难事必有所得