Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactiveCocoa subscribeNext with nil check

Most of the times when I user subscribe next, Ill check if the value isn't nil first, like so:

[[RACObserve(self.viewModel, stockViewModel.stock.imageURL) takeUntil:[self takeUntil]] subscribeNext:^(id
    value) {
        @strongify(self);

//Check if not nil
if (value) {
//Do somthing
}

    }];

Insted of doing this every time, Im trying to right a category for RACSignal that will preform this check for me, but I'm not sure how can i get the value (not the block value, the next value) from this:

- (RACDisposable *)subscribeNext:(void (^)(id x))nextBlock {
    NSCParameterAssert(nextBlock != NULL);

    RACSubscriber *o = [RACSubscriber subscriberWithNext:nextBlock error:NULL completed:NULL];
    return [self subscribe:o];
}

Any help? Thanks!

like image 206
MCMatan Avatar asked Dec 09 '22 04:12

MCMatan


1 Answers

The ignore operation on an RACSignal can be used to filter out specific values:

[[RACObserve(self, maybeNilProperty) ignore:nil] subscribeNext:^(id x) {
  // x can't be nil
}];
like image 200
Iain Wilson Avatar answered Dec 21 '22 03:12

Iain Wilson