OC + RAC (三) 信号中的信号

-(void)_test3{
    
    RACSubject *signalofsignal = [RACSubject subject]; //信号中的信号(也就是发送的数据是信号)
    RACSubject *signal1 = [RACSubject subject];
    RACSubject *signal2 = [RACSubject subject];
    RACSubject *signal3 = [RACSubject subject];
    RACSubject *signal4 = [RACSubject subject];
    
    //订阅方式1
    //    [signalofsignal subscribeNext:^(id  _Nullable x) {
    //
    //        [x subscribeNext:^(id  _Nullable x) {
    //
    //            NSLog(@"接收信号中的信号的结果%@",x);
    //        }];
    //    }];
    
    //订阅方式2 (接收到最新的那个信号)
    [signalofsignal.switchToLatest subscribeNext:^(id  _Nullable x) {
        
        NSLog(@"用 switchToLatest订阅 %@",x);
    }];
    
    [signalofsignal sendNext:signal1];
    [signalofsignal sendNext:signal2];
    [signalofsignal sendNext:signal3];
    [signalofsignal sendNext:signal4];
    
    //发送多个信号
    [signal1 sendNext:@"1"];
    [signal2 sendNext:@"2"];
    [signal3 sendNext:@"3"];
    [signal4 sendNext:@"4"];
    
}

 

上一篇:OC + RAC (十) 常用宏


下一篇:OC + RAC (四) combineLatest和merg