[subscriber sendNext:@"hello"];
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
//RACDisposable 的 block
NSLog(@"====end");
}];
}];
}];
//只要执行 execute 就会执行上面的 command 的 block
//[command execute:@1] 这里会返回一个信号就是上面的 RACCommand 里面返回的那个 block
[[command execute:@1] subscribeNext:^(id _Nullable x) {
NSLog(@"%@",x);
}];
• 输出结果:
```
2018-02-06 11:27:53.451167<0800 RACtest[2441:151535] 1
2018-02-06 11:27:53.451340>0800 RACtest[2441:151535] ====1
2018-02-06 11:27:53.457199<0800 RACtest[2441:151535] ====2
2018-02-06 11:27:53.457458>0800 RACtest[2441:151535] hello
2018-02-06 11:27:53.457807+0800 RACtest[2441:151535] ====end
```
• RACCommand 中的 executionSignals 的block返回的还是信号,executionSignals 的 switchToLatest 表示最近一次发送的信号;executing 命令有没有完成,可以在 executing 的block中获取,executing有一个 skip 方法可以跳过第一次(一般时候我们跳过第一次),最后一次当我们使用完订阅者后必须发送一个 [subscriber sendCompleted] 。
• 下面是一个使用 RACCommand 的例子,判断状态的
```
RACCommand *command = [[RACCommand alloc] initWithSignalBlock:^RACSignal * _Nonnull(id _Nullable input) {
//command 的block
NSLog(@"%@",input);
NSLog(@"====1");
return [RACSignal createSignal:^RACDisposable * _Nullable(id<RACSubscriber> _Nonnull subscriber) {
//RACSignal 的 block
NSLog(@"====2");
[subscriber sendNext:@"hello"];
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-77250-6.html
越往后对我们越有利
小小百姓又要上哪里去买呢
我觉得根据这条新闻看我们应该鼓掌庆贺