ReactiveCocoa subscribeNext 没有检查
ReactiveCocoa subscribeNext with nil check
大多数时候当我下次订阅时,我会先检查值是否不为零,就像这样:
[[RACObserve(self.viewModel, stockViewModel.stock.imageURL) takeUntil:[self takeUntil]] subscribeNext:^(id
value) {
@strongify(self);
//Check if not nil
if (value) {
//Do somthing
}
}];
我每次都这样做,我试图为 RACSignal 正确设置一个类别,它将为我执行此检查,但我不确定如何获取值(不是块值,下一个值)来自:
- (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
}];
大多数时候当我下次订阅时,我会先检查值是否不为零,就像这样:
[[RACObserve(self.viewModel, stockViewModel.stock.imageURL) takeUntil:[self takeUntil]] subscribeNext:^(id
value) {
@strongify(self);
//Check if not nil
if (value) {
//Do somthing
}
}];
我每次都这样做,我试图为 RACSignal 正确设置一个类别,它将为我执行此检查,但我不确定如何获取值(不是块值,下一个值)来自:
- (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
}];