RAC单个信号的变换

2016-12-23  本文已影响229人  wutongyu

[TOC]

信号类型

RACSignal *signal1 = [RACSignal return:@"Some Value"];
RACSignal *signal2 = [RACSignal error:errorObject];
RACSignal *signal3 = [RACSignal empty];
RACSignal *gignal4 = [RACSignal never];

    RACSignal *signal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        [subscriber sendNext:@1];
        [subscriber sendNext:@2];
        [subscriber sendError:errorObject];
        [subscriber sendCompleted];
        return [RACDisposable disposableWithBlock:^{
            
        }];
    }];
RACSignal *signal = [self.view rac_signalForSelector:@selector(setFrame:)];
RACSignal *signal = [self.button rac_signalForControlEvents:UIControlEventTouchUpInside];
RACSignal *signal = [self.view rac_willDeallocSignal];
RACSignal *signal = RACObserve(self.view, backgroundColor);

[self.view rac_liftSelector:@selector(convertRect:toView:) withSignals:signal1, signal2, nil];
[self.view rac_liftSelector:@selector(convertPoint:toView:) withSignalsFromArray:@[signql3, signal4]];
[self.view rac_liftSelector:@selector(convertRect:toLayer:) withSignalOfArguments:signal];
RACSignal *signal = [signal map:^id(id value) {
   return [value substringFromIndex:1];
}];
RACSignal *signal = sequence.signal;

对值的操作


Snip20161223_8.png Snip20161223_9.png Snip20161223_10.png
- (RACSignal *)not;
- (RACSignal *)and;
- (RACSignal *)or;
- (RACSignal *)reduceApply;
- (RACSignal *)materialize;
- (RACSignal *)dematerialize;

对数量的变换


Snip20161223_11.png Snip20161223_12.png
// 忽略所有的值
- (RACSignal *)ignoreValues;

// 去重、当上一次的值和当前的值有明显的变化就会发出信号,否则会被忽略掉
- (RACSignal *)distinctUntilChanged;
Snip20161223_13.png Snip20161223_15.png
// 取最后N次的信号,前提条件,订阅者必须调用完成,因为只有完成,就知道总共有多少信号.
- (RACSignal *)takeLast:(NSUInteger)count;
// 获取信号直到某个信号执行完成
- (RACSignal *)takeUntilBlock:(BOOL (^)(id x))predicate;
// 跳过信号直到某个信号执行完成
- (RACSignal *)skipUntilBlock:(BOOL (^)(id x))predicate;
- (RACSignal *)skipWhileBlock:(BOOL (^)(id x))predicate;
- (RACSignal *)any;
- (RACSignal *)any:(BOOL (^)(id object))predicateBlock;
- (RACSignal *)all:(BOOL (^)(id object))predicateBlock;

- 增加操作

Snip20161223_16.png Snip20161223_17.png Snip20161223_18.png Snip20161223_20.png Snip20161223_21.png Snip20161223_22.png Snip20161223_23.png

对时间的操作

Snip20161223_25.png

delay: 延时

Snip20161223_26.png Snip20161223_27.png Snip20161223_28.png

组合操作

Snip20161223_29.png Snip20161223_30.png Snip20161223_31.png Snip20161223_32.png Snip20161223_33.png Snip20161223_34.png Snip20161223_35.png Snip20161223_36.png Snip20161223_37.png Snip20161223_38.png
上一篇下一篇

猜你喜欢

热点阅读