• 20180119-01-RACSignal的基础


    一.获取一个信号的方式

      1.单元信号

        RACSignal *signal1 = [RACSignal return:@"Some Value"];
        RACSignal *signal2 = [RACSignal error:[NSError errorWithDomain:NSCocoaErrorDomain code:999 userInfo:nil]];
        RACSignal *signal3 = [RACSignal empty];
        RACSignal *signal4 = [RACSignal never];

      2.动态信号

     RACSignal *signal5 = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            [subscriber sendNext:@1];
            [subscriber sendNext:@2];
            [subscriber sendCompleted];
            return [RACDisposable disposableWithBlock:^{
                NSLog(@"信号已销毁");
            }];
        }];

      3.cocoa桥接

     RACSignal *signal6 = [self.view rac_signalForSelector:@selector(setFrame:)];
     RACSignal *signal7 = [self.btn rac_signalForControlEvents:UIControlEventTouchUpInside];
     RACSignal *signal8 = [self.view rac_willDeallocSignal];
     RACSignal *singal9 = RACObserve(self.view, backgroundColor)

      4.信号变换

     RACSignal *signall10 = [signal1 map:^id _Nullable(id  _Nullable value) {
            return [value substringFromIndex:1];
        }];

      5.序列变换

    RACSequence *sequence = @[@1,@2,@3].rac_sequence;
    RACSignal *signal11 = sequence.signal;

    二.订阅一个信号的方式

      1.订阅方法

    [signal11 subscribeNext:^(id  _Nullable x) {
            NSLog(@"next value is %@",x);
        } error:^(NSError * _Nullable error) {
            NSLog(@"Ops Get some error:%@",error);
        } completed:^{
            NSLog(@"It finish success");
        }];

      2.绑定

     RAC(self.view,backgroundColor) = signal9;

      3.Cocoa桥接

    [self.view rac_liftSelector:@selector(convertPoint:toView:) withSignals:signal1,signal2, nil];
    [self.view rac_liftSelector:@selector(convertPoint:toView:) withSignalsFromArray:@[signal1,signal2]];
    [self.view rac_liftSelector:@selector(convertPoint:toView:) withSignalOfArguments:signal5];

      4.订阅过程

     RACSignal *signal = [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            [subscriber sendNext:@1];
            [subscriber sendNext:@2];
            [subscriber sendCompleted];
            return [RACDisposable disposableWithBlock:^{
                NSLog(@"信号销毁");
            }];
        }];
        
    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 finish success");
        }];
    [disposable dispose];

    三.信号的变换和组合

    四.RACSignal的各类操作

    单个信号的变换

  • 相关阅读:
    T-SQL逻辑查询的各阶段
    linqtosql(GroupBy/Having/Count/Sum/Min/Max/Avg操作符)
    jquery获取select下拉框的值以及change时间绑定
    英汉翻译功能的简单实现
    jQuery zTree默认加载一级几点
    Linq第一篇
    vs2015+win10搭开发环境
    asp.net mvc 中使用静态页
    .net中的异步操作
    (转载)TFS2013安装+配置
  • 原文地址:https://www.cnblogs.com/it-q/p/7989652.html
Copyright © 2020-2023  润新知