美文网首页
RAC的升阶操作

RAC的升阶操作

作者: 凯司机 | 来源:发表于2021-05-08 18:02 被阅读0次

// 信号高阶操作

// 通过信号转换

// 升阶 value转signal

// 降阶 signal转value

升阶:

// 实际应用场景——升阶 value转signal
// 蛋疼的订阅方法
RACSignal *signalA = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
    [subscriber sendNext:@1];
    [subscriber sendNext:@2];
    [subscriber sendNext:@3];
    [subscriber sendNext:@4];
    [subscriber sendNext:@5];
    [subscriber sendCompleted];
    return [RACDisposable disposableWithBlock:^{
        NSLog(@"signalA1完成");
    }];
}];
RACSignal *signalB = [signalA map:^id(id value) {
  return [RACSignal return:value];
}];

[[signalB subscribeNext:^(RACSignal *x) {
  [x subscribeNext:^(id x) {
    NSLog(@"subscribeNext:%@",x);
  }];
}] dispose];

2021-04-15 16:32:26.148228+0800 XXXXXX[3834:1102013] [DYMTLInitPlatform] platform initialization successful

2021-04-15 16:32:27.193424+0800 XXXXXX[3834:1101906] subscribeNext:1

2021-04-15 16:32:27.193515+0800 XXXXXX[3834:1101906] subscribeNext:2

2021-04-15 16:32:27.193551+0800 XXXXXX[3834:1101906] subscribeNext:3

2021-04-15 16:32:27.193574+0800 XXXXXX[3834:1101906] subscribeNext:4

2021-04-15 16:32:27.193595+0800 XXXXXX[3834:1101906] subscribeNext:5

2021-04-15 16:32:27.194864+0800 XXXXXX[3834:1101906] signalA1完成

相关文章

网友评论

      本文标题:RAC的升阶操作

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