美文网首页
RAC的combineLatestWith、combineLat

RAC的combineLatestWith、combineLat

作者: 凯司机 | 来源:发表于2021-05-07 09:42 被阅读0次

    组合操作——combineLatestWith、combineLatest:

    // 组合操作——combineLatestWith、combineLatest:按照信号执行时间顺序依次进行叠加,列出全部的元素。形成元组一一对应。
    // 信号一方先结束另一方也跟着结束。
    RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
      [subscriber sendNext:@1];
      [subscriber sendNext:@2];
      [subscriber sendNext:@3];
      [subscriber sendNext:@4];
      [subscriber sendNext:@5];
    // [subscriber sendError:[NSError new]];
      [subscriber sendCompleted];
      return [RACDisposable disposableWithBlock:^{
        NSLog(@"signalA完成");
      }];
    }];
    
    RACSignal *signalB = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
      [subscriber sendNext:@11];
      [subscriber sendNext:@22];
    // [subscriber sendError:[NSError new]];
      [subscriber sendNext:@44];
      [subscriber sendCompleted];
      return [RACDisposable disposableWithBlock:^{
        NSLog(@"signalB完成");
      }];
    }];
    
    //    RACSignal *signalC = [signalA combineLatestWith:signalB];
    //    RACSignal *signalC = [RACSignal combineLatest:@[signalA, signalB]];
    RACSignal *signalC = [RACSignal combineLatest:RACTuplePack(signalA, signalB)];
    [[signalC subscribeNext:^(id x) {
      NSLog(@"subscribeNext:%@",x);
    }] dispose];
    

    2021-04-15 11:06:31.791936+0800 xxxxxx[3465:1037447] signalA完成

    2021-04-15 11:06:31.792967+0800 xxxxxx[3465:1037447] subscribeNext:<RACTuple: 0x170011610> (

    5,

    11

    )

    2021-04-15 11:06:31.793053+0800 xxxxxx[3465:1037447] subscribeNext:<RACTuple: 0x170011620> (

    5,

    22

    )

    2021-04-15 11:06:31.793098+0800 xxxxxx[3465:1037447] subscribeNext:<RACTuple: 0x1700116a0> (

    5,

    44

    )

    2021-04-15 11:06:31.793137+0800 xxxxxx[3465:1037447] signalB完成

    相关文章

      网友评论

          本文标题:RAC的combineLatestWith、combineLat

          本文链接:https://www.haomeiwen.com/subject/romirltx.html