大多数时候当我下次订阅时,我会先检查值是否不为 nil,如下所示:
[[RACObserve(self.viewModel, stockViewModel.stock.imageURL) takeUntil:[self takeUntil]] subscribeNext:^(id
value) {
@strongify(self);
//Check if not nil
if (value) {
//Do somthing
}
}];
我每次都这样做,我试图为 RACSignal 正确设置一个类别,它将为我执行此检查,但我不确定如何从中获取值(不是 block 值,下一个值) :
- (RACDisposable *)subscribeNext:(void (^)(id x))nextBlock {
NSCParameterAssert(nextBlock != NULL);
RACSubscriber *o = [RACSubscriber subscriberWithNext:nextBlock error:NULL completed:NULL];
return [self subscribe:o];
}
有什么帮助吗?谢谢!
最佳答案
RACSignal 上的ignore
操作可用于过滤掉特定值:
[[RACObserve(self, maybeNilProperty) ignore:nil] subscribeNext:^(id x) {
// x can't be nil
}];
关于ios - ReactiveCocoa subscribeNext 没有检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28261045/