Objective-C

RACSignal的使用基础

2019-07-02  本文已影响0人  Jimmy_L_Wang

获得信号的方式

订阅一个信号的方式

订阅过程

 RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
        [subscriber sendNext:@1];
        [subscriber sendNext:@2];
        [subscriber sendCompleted];
        return [RACDisposable disposableWithBlock:^{
            NSLog(@"disposed");
        }];
    }];
    
    RACDisposable *disposable = [signal subscribeNext:^(id  _Nullable x) {
        NSLog(@"next value is %@", x);
    } error:^(NSError * _Nullable error) {
        NSLog(@"Ops! Get some error:%@", error);
    } completed:^{
        NSLog(@"It finished");
    }];
    
    [disposable dispose];

元祖-RACTuple

  RACTuple *tuple = RACTuplePack(@1, @"second");
    
    id first = tuple.first;
    id second = tuple.second;
    id last = tuple.last;
    
    id index2 = tuple[1];//second
    NSLog(@"%@", index2);
    
    RACTupleUnpack(NSNumber *num, NSString *str) = tuple;
    NSLog(@"num is %@", num); //num is 1
}

信号示例

信号示例.png

信号定义&&信号订阅

信号订阅与定义.png

单元信号图示

单元信号.png

信号的变换和组合

信号的变换.png 信号的组合.png

单个信号的变换

单个信号的变换.png

对值操作

Map
map.png
MapReplace
map_replace.png
ReduceEach(只用于元祖)
reduce_each.png
其他
其他.png

对数量操作

Filter(减少数量)
filter.png
ignore(减少数量)
ignore.png
take(减少数量)
take.png
skip(减少数量)
skip.png
take&skip其他(减少数量)
take_skip.png
混合操作(减少数量)
混合操作.png
StartWith(增加数量)
start_with.png
Repeat(增加数量)
repeat.png
retry
retry.png
副作用操作
副作用操作.png
数量操作-collect
collect.png
数量操作-aggregate
aggregate.png
数量操作-scan
scan.png
aggregate && scan变种
agg_scan.png

时间操作-有用的信号

time_signal.png

时间操作-Delay

delay.png

时间操作-Throttle

throttle.png

时间操作-类似Throttle的方法

buffer.png

多个信号组合

concat
concat.png
merge
merge.png merger运用.png
组合操作--zip
zip.png

组合操作-combineLatest

combine_latest.png
组合操作- Zip&CombineLatest
zip_combinelatest.png
组合操作 - Sample
sample.png
组合操作--TakeUntil
take_until.png
组合操作--TakeUntilReplacement
take_until_replace.png
上一篇 下一篇

猜你喜欢

热点阅读