ReactiveCocoa入門到實(shí)戰(zhàn) 學(xué)習(xí)筆記(一)

ReactiveCocoa操作詳解


內(nèi)容大綱

  • RACSignal使用基礎(chǔ)
  • RACSignal各類操作

RACSignal使用基礎(chǔ)

1. 獲得一個(gè)信號(hào)
  • 單元信號(hào)
RACSignal *signal1 = [RACSignal return:@"Some Value"]; // 創(chuàng)建一個(gè)值信號(hào)
RACSignal *signal2 = [RACSignal error:errorObject]; // 創(chuàng)建一個(gè)錯(cuò)誤信號(hào)
RACSignal *signal3 = [RACSignal empty]; // 創(chuàng)建一個(gè)空信號(hào)
RACSignal *signal4 = [RACSignal never]; // 創(chuàng)建一個(gè)無盡的信號(hào)
  • 動(dòng)態(tài)信號(hào)
RACSignal *signal5 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
       
        [subscriber sendNext:@1];
        [subscriber sendNext:@1];
        [subscriber sendNext:@1];
        [subscriber sendError:errorObject];
        [subscriber sendCompleted];
        return [RACDisposable disposableWithBlock:^{
            
            NSLog(@"disposabled");
        }];
    }];
  • Cocoa橋接
RACSignal *signal6 = [view rac_signalForSelector:@selector(setFrame:)];
RACSignal *signal7 = [view rac_signalForControlEvents:UIControlEventTouchUpInside];
RACSignal *signal8 = [view rac_willDeallocSignal];
RACSignal *signal9 = RACObserve(view, currentTitle);
  • 信號(hào)變換
RACSignal *signal10 = [signal1 map:^id(id value) {
    return [value substringFromIndex:1];
}];
  • 序列轉(zhuǎn)換
RACSignal *signal11 = @[@1, @2, @3, @4].rac_sequence.signal;
2. 訂閱一個(gè)信號(hào)的方式
  • 訂閱方法
RACSignal *signal11 = @[@1, @2, @3, @4].rac_sequence.signal;
[signal11 subscribeNext:^(id x) {
    NSLog(@"next vlaue is %@", x);
} error:^(NSError *error) {
    NSLog(@"Ops! Get some error: %@", error);
} completed:^{
    NSLog(@"It is finished");
}];
  • 綁定
RAC(view, backgroundColor) = signal1;
  • Cocoa橋接
[view rac_liftSelector:@selector(convertPoint:toView:) withSignals:signal1, signal2, nil];
[view rac_liftSelector:@selector(convertPoint:toView:) withSignals:@[signal1, signal2]];
[view rac_liftSelector:@selector(convertPoint:toView:) withSignals:signal5];

RACSignal各類操作

1. 單個(gè)信號(hào)的變換
1.1 對(duì)信號(hào)值得操作
  • Map
    map操作可以獲取到信號(hào)發(fā)出的value,通過block返回以得到一個(gè)新的信號(hào)
    RACSignal *signal12 = [signal11 map:^id(id value) {
        return @([value integerValue] - 1);;
    }];
    [signal12 subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];

    /*
      2021-08-03 22:29:42.269178+0800 RACTestOne[34577:1684307] 0
      2021-08-03 22:29:42.269282+0800 RACTestOne[34577:1684307] 1
      2021-08-03 22:29:42.269386+0800 RACTestOne[34577:1684307] 2
      2021-08-03 22:29:42.269524+0800 RACTestOne[34577:1684307] 3
    */
  • MapReplace
    將所有的信號(hào)返回替換為一個(gè)新的對(duì)象佳头,是map的簡易版
RACSignal *signal13 = [signal12 mapReplace:@1];
  • ReduceEach
    取出元祖信號(hào)中的每一個(gè)值宿饱,并返回一個(gè)新的值
RACSignal *signal1 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        
        [subscriber sendNext:RACTuplePack(@1, @2, @3)];
        [subscriber sendNext:RACTuplePack(@2, @3)];
        [subscriber sendNext:RACTuplePack(@3, @4)];
        [subscriber sendNext:RACTuplePack(@4, @5)];
        
        [subscriber sendCompleted];
        
        return nil;
    }];
    
    
    RACSignal *signal2 = [signal1 reduceEach:^NSNumber *(NSNumber *first, NSNumber *second, NSNumber *third){
        
        return @(first.integerValue + second.integerValue + third.integerValue);
    }];
    
    [signal2 subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    
    /*
    2021-08-04 08:42:10.251210+0800 RACTestOne[34956:1706970] 6
    2021-08-04 08:42:10.251318+0800 RACTestOne[34956:1706970] 5
    2021-08-04 08:42:10.251403+0800 RACTestOne[34956:1706970] 7
    2021-08-04 08:42:10.251457+0800 RACTestOne[34956:1706970] 9
     */

可以看到道批,當(dāng)元祖數(shù)量不同時(shí),reduceEach會(huì)將取不到的值設(shè)置為 nil 而不會(huì)出現(xiàn)崩潰傅寡。

  • not
    對(duì)一個(gè)僅返回BOOL類型的信號(hào)取反
    RACSignal *signal3 = [RACSignal return:@YES];
    [[signal3 not] subscribeNext:^(id x) {
       
        NSLog(@"%@", [x boolValue] ? @"YES" : @"NO");
    }];
    
    /*
     2021-08-04 08:47:17.944753+0800 RACTestOne[35009:1710481] NO
     */
  • and
    對(duì)一個(gè)發(fā)送了一個(gè)或多個(gè)長度不為零的元祖的信號(hào)侦鹏,且元祖內(nèi)部的值全都是由布爾值組成的俊抵,將每個(gè)元祖內(nèi)的所有值做與操作厂榛,返回結(jié)果盖矫。
  • or
    對(duì)一個(gè)發(fā)送了一個(gè)或多個(gè)長度不為零的元祖的信號(hào),且元祖內(nèi)部的值全都是由布爾值組成的击奶,將每個(gè)元祖內(nèi)的所有值做或操作,返回結(jié)果责掏。
    RACSignal *signal3 = [RACSignal return:RACTuplePack(@YES, @NO, @YES)];
    [[signal3 and] subscribeNext:^(id x) {
       
        NSLog(@"AND: %@", [x boolValue] ? @"YES" : @"NO");
    }];
    
    [[signal3 or] subscribeNext:^(id x) {
       
        NSLog(@"OR: %@", [x boolValue] ? @"YES" : @"NO");
    }];
    
    /*
     2021-08-04 08:58:21.128811+0800 RACTestOne[35195:1719493] AND: NO
     2021-08-04 08:58:21.128980+0800 RACTestOne[35195:1719493] OR: YES
     */
  • reduceApply
    reduceApply需要對(duì)一個(gè)合并信號(hào)做處理柜砾,第一個(gè)信號(hào)返回一個(gè)處理后面幾個(gè)信號(hào)發(fā)送值得處理函數(shù)Block,后面幾個(gè)信號(hào)返回等待被處理的數(shù)值换衬。
    RACSignal *adder = [RACSignal return:^NSNumber *(NSNumber *one, NSNumber *two, NSNumber *three) {
       
        return @([one integerValue] + [two integerValue] + [three integerValue]);
    }];
    
    RACSignal *as = [RACSignal return:@1];
    RACSignal *bs = [RACSignal return:@2];
    RACSignal *cs = [RACSignal return:@3];
    
    [[[RACSignal combineLatest:@[adder, as, bs, cs]] reduceApply] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    
    /*
     2021-08-04 09:14:58.073673+0800 RACTestOne[35453:1730815] 6
     */
  • materialize
    返回一個(gè)新的信號(hào)痰驱,原始信號(hào)返回的類型被包裝成RACEven返回
    RACSignal *adder = [RACSignal return:^NSNumber *(NSNumber *one, NSNumber *two, NSNumber *three) {
       
        return @([one integerValue] + [two integerValue] + [three integerValue]);
    }];
    
    [[adder materialize] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    
    /*
     2021-08-04 09:19:57.367154+0800 RACTestOne[35556:1734750] <RACEvent: 0x600002a641a0>{ next = <__NSGlobalBlock__: 0x1000c0048> }
     2021-08-04 09:19:57.367420+0800 RACTestOne[35556:1734750] <RACEvent: 0x600002a74100>{ completed }
     */
  • dematerialize
    對(duì)materialize包裝過的信號(hào)進(jìn)行解包,將包裝成RACEven的信號(hào)還原成內(nèi)部包裝的值
    RACSignal *signal3 = [RACSignal return:RACTuplePack(@1, @2, @3)];

    [[[signal3 materialize] dematerialize] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    
    /*
     2021-08-04 09:23:13.567598+0800 RACTestOne[35639:1738327] <RACTuple: 0x600003fa44f0> (
         1,
         2,
         3
     )
     */
1.2 對(duì)信號(hào)數(shù)量的操作
  • Filter
    篩選過濾掉部分信號(hào)的返回瞳浦,減少信號(hào)返回的數(shù)量
    [[@[@1, @2, @3, @4, @5, @6].rac_sequence.signal filter:^BOOL(id value) {
        return [value integerValue] % 2 == 0;
    }] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:27:25.854256+0800 RACTestOne[35708:1741471] 2
     2021-08-04 09:27:25.854370+0800 RACTestOne[35708:1741471] 4
     2021-08-04 09:27:25.854520+0800 RACTestOne[35708:1741471] 6
     */
  • Ignore
    忽略掉制定的返回值
    [[@[@1, @2, @3, @4, @5, @6].rac_sequence.signal
      ignore:@2] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:28:57.476956+0800 RACTestOne[35736:1742733] 1
     2021-08-04 09:28:57.477062+0800 RACTestOne[35736:1742733] 3
     2021-08-04 09:28:57.477110+0800 RACTestOne[35736:1742733] 4
     2021-08-04 09:28:57.477148+0800 RACTestOne[35736:1742733] 5
     2021-08-04 09:28:57.477264+0800 RACTestOne[35736:1742733] 6
     */
  • ignoreValues
    忽略掉所有的next信號(hào)返回
    [[@[@1, @2, @3, @4, @5, @6].rac_sequence.signal ignoreValues] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
  • distinctUntilChanged
    當(dāng)出現(xiàn)連續(xù)的重復(fù)項(xiàng)時(shí)担映,只取最后一項(xiàng)返回
    [[@[@1, @1, @2, @2, @3, @2, @4, @5, @6].rac_sequence.signal distinctUntilChanged] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:32:14.037896+0800 RACTestOne[35834:1746249] 1
     2021-08-04 09:32:14.037999+0800 RACTestOne[35834:1746249] 2
     2021-08-04 09:32:14.038068+0800 RACTestOne[35834:1746249] 3
     2021-08-04 09:32:14.038108+0800 RACTestOne[35834:1746249] 2
     2021-08-04 09:32:14.038189+0800 RACTestOne[35834:1746249] 4
     2021-08-04 09:32:14.038236+0800 RACTestOne[35834:1746249] 5
     2021-08-04 09:32:14.038291+0800 RACTestOne[35834:1746249] 6
     */
  • Take
    取固定數(shù)量的信號(hào)返回
    [[@[@1, @1, @2, @2, @3, @2, @4, @5, @6].rac_sequence.signal take:2] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     021-08-04 09:38:15.003595+0800 RACTestOne[35907:1749829] 1
     2021-08-04 09:38:15.003683+0800 RACTestOne[35907:1749829] 1
     */
  • Skip
    跳過固定數(shù)量的信號(hào)
    [[@[@1, @1, @2, @2, @3, @2, @4, @5, @6].rac_sequence.signal skip:2] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:39:04.452936+0800 RACTestOne[35945:1750781] 2
     2021-08-04 09:39:04.453019+0800 RACTestOne[35945:1750781] 2
     2021-08-04 09:39:04.453232+0800 RACTestOne[35945:1750781] 3
     2021-08-04 09:39:04.453386+0800 RACTestOne[35945:1750781] 2
     2021-08-04 09:39:04.453442+0800 RACTestOne[35945:1750781] 4
     2021-08-04 09:39:04.453485+0800 RACTestOne[35945:1750781] 5
     2021-08-04 09:39:04.453523+0800 RACTestOne[35945:1750781] 6
     */
  • takeLast
    取最后幾個(gè)信號(hào)
    [[@[@1, @1, @2, @2, @3, @2, @4, @5, @6].rac_sequence.signal takeLast:2] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:39:50.624034+0800 RACTestOne[35965:1751667] 5
     2021-08-04 09:39:50.624094+0800 RACTestOne[35965:1751667] 6
     */
  • takeUntilBlock
    根據(jù)block判斷是否終止取值,如果block返回YES叫潦,則終止取值
    [[@[@1, @1, @2, @0, @3, @2, @4, @5, @6].rac_sequence.signal takeUntilBlock:^BOOL(id x) {
        
        return [x integerValue] == 0;
    }] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:41:29.019555+0800 RACTestOne[36008:1753297] 1
     2021-08-04 09:41:29.019634+0800 RACTestOne[36008:1753297] 1
     2021-08-04 09:41:29.019721+0800 RACTestOne[36008:1753297] 2
     */
  • takeWhileBlock
    與takeUntilBlock相反蝇完,返回YES時(shí)繼續(xù)取值,返回NO時(shí)終止取值
    [[@[@1, @1, @2, @0, @3, @2, @4, @5, @6].rac_sequence.signal takeWhileBlock:^BOOL(id x) {
        
        return [x integerValue] != 0;
    }] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 09:41:29.019555+0800 RACTestOne[36008:1753297] 1
     2021-08-04 09:41:29.019634+0800 RACTestOne[36008:1753297] 1
     2021-08-04 09:41:29.019721+0800 RACTestOne[36008:1753297] 2
     */
  • skipUntilBlock

  • skipWhileBlock
    同理

  • any
    收到任何信號(hào)時(shí)矗蕊,返回一個(gè)YES

  • any:
    根據(jù)block短蜕,遍歷判斷每一個(gè)信號(hào),直到找到符合條件的信號(hào)則返回YES傻咖,如果一直沒有則返回 NO

  • all:
    遍歷查找朋魔,出現(xiàn)第一個(gè)不符合block條件的數(shù)值則返回NO,所有數(shù)值都符合則返回YES

   [[@[@2, @1, @2, @3, @5].rac_sequence.signal all:^BOOL(id object) {
        
        NSInteger result = [object integerValue] % 2;
        return result == 0;
        
    }] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
  • startWith
    往頭部添加一個(gè)信號(hào)
  • repeat
    對(duì)信號(hào)無限重播
  • retry:
    遇到錯(cuò)誤時(shí)進(jìn)行重試卿操,參數(shù)為重試的次數(shù)
  • collect
    將所有收到的信號(hào)打包成一個(gè)數(shù)組警检,一次性返回
  • Aggregate
    折疊函數(shù)孙援,對(duì)每個(gè)信號(hào)根據(jù)block規(guī)則進(jìn)行折疊,最終一次性返回
    [[@[@2, @1, @2, @3, @5].rac_sequence.signal
      aggregateWithStart:@0 reduce:^id(id running, id next) {
        
        return @([running integerValue] + [next integerValue]);
        
    }] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 10:54:45.216450+0800 RACTestOne[36763:1783653] 13
     */
  • scan:
    掃描函數(shù)扇雕,也會(huì)對(duì)信號(hào)進(jìn)行折疊拓售,但是每一次的折疊計(jì)算都會(huì)被返回
    [[@[@2, @1, @2, @3, @5].rac_sequence.signal
      scanWithStart:@0 reduce:^id(id running, id next) {
        
        return @([running integerValue] + [next integerValue]);
        
    }] subscribeNext:^(id x) {
        NSLog(@"%@", x);
    }];
    /*
     2021-08-04 10:55:51.862320+0800 RACTestOne[36810:1785060] 2
     2021-08-04 10:55:51.862408+0800 RACTestOne[36810:1785060] 3
     2021-08-04 10:55:51.862454+0800 RACTestOne[36810:1785060] 5
     2021-08-04 10:55:51.862511+0800 RACTestOne[36810:1785060] 8
     2021-08-04 10:55:51.862568+0800 RACTestOne[36810:1785060] 13
     */
  • aggregateWithStartFactory
    與Aggregate功能相同,只是start是通過外接一個(gè)block返回的
1.3 對(duì)信號(hào)維度的操作
  • contact
    組合多個(gè)信號(hào)洼裤,一個(gè)信號(hào)結(jié)束以后再執(zhí)行下一個(gè)信號(hào)
    RACSignal *signal = [[@[@1,@1,@1, @2, @3, @4, @5].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }] concat];
    [signal subscribeNext:^(id x) {
        NSLog(@"%@-%@",x, [NSDate date]);
    }];
    /*
     2021-08-04 11:17:51.630939+0800 RACTestOne[37128:1799867] 1-Wed Aug  4 11:17:51 2021
     2021-08-04 11:17:52.730100+0800 RACTestOne[37128:1799868] 1-Wed Aug  4 11:17:52 2021
     2021-08-04 11:17:53.741029+0800 RACTestOne[37128:1799868] 1-Wed Aug  4 11:17:53 2021
     2021-08-04 11:17:55.843420+0800 RACTestOne[37128:1799867] 2-Wed Aug  4 11:17:55 2021
     2021-08-04 11:17:59.060781+0800 RACTestOne[37128:1799866] 3-Wed Aug  4 11:17:59 2021
     2021-08-04 11:18:03.399525+0800 RACTestOne[37128:1799867] 4-Wed Aug  4 11:18:03 2021
     2021-08-04 11:18:08.747093+0800 RACTestOne[37128:1799991] 5-Wed Aug  4 11:18:08 2021
     */

可以看到邻辉,每個(gè)信號(hào)都等待到了信號(hào)延時(shí)結(jié)束。

  • Merge
    兩個(gè)信號(hào)被組合成了一個(gè)信號(hào)腮鞍,并依照時(shí)間軸交替執(zhí)行
    RACSignal *signal1 = [@[@1, @3,@5].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }];
    RACSignal *signal2 = [@[@2, @4, @6].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }];
    RACSignal *signal3 = [[signal1 merge:signal2] flatten];
    [signal3 subscribeNext:^(id x) {
        NSLog(@"%@-%@",x, [NSDate date]);
    }];
    /*
     2021-08-04 11:22:05.839697+0800 RACTestOne[37210:1803227] 1-Wed Aug  4 11:22:05 2021
     2021-08-04 11:22:06.826184+0800 RACTestOne[37210:1803227] 2-Wed Aug  4 11:22:06 2021
     2021-08-04 11:22:07.926575+0800 RACTestOne[37210:1803227] 3-Wed Aug  4 11:22:07 2021
     2021-08-04 11:22:08.940237+0800 RACTestOne[37210:1803225] 4-Wed Aug  4 11:22:08 2021
     2021-08-04 11:22:09.954859+0800 RACTestOne[37210:1803227] 5-Wed Aug  4 11:22:09 2021
     2021-08-04 11:22:11.038293+0800 RACTestOne[37210:1803225] 6-Wed Aug  4 11:22:11 2021
     */
  • zip
    將A,B兩個(gè)信號(hào)組成一個(gè)元祖信號(hào)值骇,并且嚴(yán)格執(zhí)行(A,B)(A, B)模式,兩個(gè)信號(hào)的返回必須成對(duì)移国,無法組隊(duì)的信號(hào)不返回
    RACSignal *signal1 = [[@[@1, @3,@5].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }] flatten];
    RACSignal *signal2 = [[@[@2, @4].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }] flatten];
    RACSignal *signal3 = [signal1 zipWith:signal2];
    [signal3 subscribeNext:^(id x) {
        NSLog(@"%@",x);
    }];
    /*
     2021-08-04 11:27:42.739708+0800 RACTestOne[37338:1809066] <RACTuple: 0x60000140c030> (
         1,
         2
     )
     2021-08-04 11:27:44.976464+0800 RACTestOne[37338:1809066] <RACTuple: 0x600001430060> (
         3,
         4
     )
     */
  • combineLatest
    與zip類似吱瘩,組合兩個(gè)信號(hào),但是不需要強(qiáng)制成對(duì)迹缀。A,B信號(hào)任意信號(hào)返回新值時(shí)使碾,就會(huì)觸發(fā)信號(hào)的訂閱回調(diào)
    RACSignal *signal1 = [[@[@1, @3,@5].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }] concat];
    RACSignal *signal2 = [[@[@2, @4].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }] concat];
    RACSignal *signal3 = [signal1 combineLatestWith:signal2];
    [signal3 subscribeNext:^(id x) {
        NSLog(@"%@",x);
    }];
    /*
     2021-08-04 11:29:32.056260+0800 RACTestOne[37397:1811166] <RACTuple: 0x6000006c8050> (
         1,
         2
     )
     2021-08-04 11:29:34.118925+0800 RACTestOne[37397:1811169] <RACTuple: 0x6000006c8050> (
         3,
         2
     )
     2021-08-04 11:29:36.445053+0800 RACTestOne[37397:1811166] <RACTuple: 0x6000006cc040> (
         3,
         4
     )
     2021-08-04 11:29:39.342934+0800 RACTestOne[37397:1811169] <RACTuple: 0x6000006f0020> (
         5,
         4
     )
     */
  • sample
    取樣,根據(jù)取樣信號(hào)祝懂,取出當(dāng)前信號(hào)對(duì)應(yīng)取樣節(jié)點(diǎn)時(shí)返回的值票摇。
    RACSignal *arraySignal = [@[@1, @2, @3, @4, @5, @6, @8, @10, @0].rac_sequence.signal flattenMap:^RACStream *(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }];
    
    RACSignal *timeSignal = [RACSignal interval:2 onScheduler:[RACScheduler scheduler]];
    
    [[arraySignal sample:timeSignal] subscribeNext:^(id x) {
       
        NSLog(@"%@", x);
    }];

    /*
     2021-08-04 11:48:31.610566+0800 RACTestOne[37677:1825278] 1
     2021-08-04 11:48:33.609945+0800 RACTestOne[37677:1825280] 3
     2021-08-04 11:48:35.610757+0800 RACTestOne[37677:1825280] 5
     2021-08-04 11:48:37.610773+0800 RACTestOne[37677:1825278] 6
     2021-08-04 11:48:39.610739+0800 RACTestOne[37677:1825278] 8
     */
1.4 對(duì)信號(hào)時(shí)間的操作
  • + (RACSignal *)interval:(NSTimeInterval)interval onScheduler:(RACScheduler *)scheduler;
  • + (RACSignal *)interval:(NSTimeInterval)interval onScheduler:(RACScheduler *)scheduler withLeeway:(NSTimeInterval)leeway;
    返回一個(gè)定時(shí)器信號(hào)
  • Delay
    對(duì)信號(hào)的發(fā)送時(shí)機(jī)進(jìn)行延時(shí)
    RACSignal *signal = [RACSignal interval:1 onScheduler:[RACScheduler scheduler]];
    RACSignal *signa2 = [signal delay: 1];
  • Throttle
    閥門,一定時(shí)間內(nèi)連續(xù)出現(xiàn)信號(hào)時(shí)砚蓬,只取其最后一個(gè)信號(hào)矢门。
    RACSignal *signal = [[@[@1,@1,@1, @2, @3, @4, @5].rac_sequence.signal map:^id(id value) {
        
        return [[RACSignal return:value] delay:[value doubleValue]];
    }] concat];
    [[signal throttle:3] subscribeNext:^(id x) {
        NSLog(@"%@",x);
    }];
    /*
     2021-08-04 11:14:02.913663+0800 RACTestOne[37056:1797195] 2
     2021-08-04 11:14:06.140407+0800 RACTestOne[37056:1797195] 3
     2021-08-04 11:14:10.474246+0800 RACTestOne[37056:1797195] 4
     2021-08-04 11:14:12.734156+0800 RACTestOne[37056:1797195] 5
     */
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市灰蛙,隨后出現(xiàn)的幾起案子祟剔,更是在濱河造成了極大的恐慌,老刑警劉巖摩梧,帶你破解...
    沈念sama閱讀 211,884評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件物延,死亡現(xiàn)場離奇詭異,居然都是意外死亡仅父,警方通過查閱死者的電腦和手機(jī)叛薯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,347評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來驾霜,“玉大人案训,你說我怎么就攤上這事》嗖冢” “怎么了强霎?”我有些...
    開封第一講書人閱讀 157,435評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長蓉冈。 經(jīng)常有香客問我城舞,道長轩触,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,509評(píng)論 1 284
  • 正文 為了忘掉前任家夺,我火速辦了婚禮脱柱,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘拉馋。我一直安慰自己榨为,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,611評(píng)論 6 386
  • 文/花漫 我一把揭開白布煌茴。 她就那樣靜靜地躺著随闺,像睡著了一般。 火紅的嫁衣襯著肌膚如雪蔓腐。 梳的紋絲不亂的頭發(fā)上矩乐,一...
    開封第一講書人閱讀 49,837評(píng)論 1 290
  • 那天,我揣著相機(jī)與錄音回论,去河邊找鬼散罕。 笑死,一個(gè)胖子當(dāng)著我的面吹牛傀蓉,可吹牛的內(nèi)容都是我干的芭届。 我是一名探鬼主播瘟仿,決...
    沈念sama閱讀 38,987評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼眠饮,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼暑劝!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起萨蚕,我...
    開封第一講書人閱讀 37,730評(píng)論 0 267
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蹄胰,沒想到半個(gè)月后岳遥,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,194評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡裕寨,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,525評(píng)論 2 327
  • 正文 我和宋清朗相戀三年浩蓉,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片宾袜。...
    茶點(diǎn)故事閱讀 38,664評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡捻艳,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出庆猫,到底是詐尸還是另有隱情认轨,我是刑警寧澤,帶...
    沈念sama閱讀 34,334評(píng)論 4 330
  • 正文 年R本政府宣布月培,位于F島的核電站嘁字,受9級(jí)特大地震影響恩急,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜纪蜒,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,944評(píng)論 3 313
  • 文/蒙蒙 一衷恭、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧纯续,春花似錦随珠、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,764評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至兔魂,卻和暖如春烤芦,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背析校。 一陣腳步聲響...
    開封第一講書人閱讀 31,997評(píng)論 1 266
  • 我被黑心中介騙來泰國打工构罗, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人智玻。 一個(gè)月前我還...
    沈念sama閱讀 46,389評(píng)論 2 360
  • 正文 我出身青樓遂唧,卻偏偏與公主長得像,于是被迫代替她去往敵國和親吊奢。 傳聞我的和親對(duì)象是個(gè)殘疾皇子盖彭,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,554評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容