码迷,mamicode.com
首页 > 其他好文 > 详细

OC + RAC (二) Command 命令的用法

时间:2019-05-03 18:46:09      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:init   isp   方法   inpu   订阅   表示   put   .exe   turn   

-(void)_test2{
    
    ///////////////////////////////////////Command 命令的用法 注意使用command.executionSignals去订阅时 一定要先订阅再excute
    RACCommand * command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id  _Nullable input) {
        
        NSLog(@"input = %@",input); // 就是execute后面的参数
        
        return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber>  _Nonnull subscriber) {
            
            [subscriber sendNext:@"发布信息"];
            
            return nil;
        }];
        
    }];
    
    //另一种接收信息的方法 (此方法必须在execute方法之前)
    [command.executionSignals subscribeNext:^(id  _Nullable x) {
        NSLog(@"另一种接收信息的方法 %@",x); //x是信号 得再次订阅
        [x subscribeNext:^(id  _Nullable x) {
            
            NSLog(@"另一种接收信息的方法返回结果再次订阅 %@",x);
        }];
        
    }];
    
    RACSignal *commandSigal =  [command execute:@"开始飞起来"];
    
    [commandSigal subscribeNext:^(id  _Nullable x) {
        
        NSLog(@"接收发布的信息%@",x);
        
    } error:^(NSError * _Nullable error) {
        
    } completed:^{
        
    }]; //订阅commandSigal信号
    
    NSLog(@"//////////////////////////////////////////////////////////////////////");
    ///////////////////////////////////switchToLatest表示的是最新发送的信号
    
    
}

 

OC + RAC (二) Command 命令的用法

标签:init   isp   方法   inpu   订阅   表示   put   .exe   turn   

原文地址:https://www.cnblogs.com/liuw-flexi/p/10805800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!