Search code examples
objective-cobjective-c-blocksreactive-cocoa

RACSignal combineLatest: cannot reduce


I have a horrible compile problem while trying to reduce a couple of signals.

RACSignal* contactIdentifierSignal = RACObserve(self, contactIdentifier);
RACSignal* displayNameSignal = RACObserve(self, displayName);

RACSignal* mappedThing = [RACSignal combineLatest:@[contactIdentifierSignal, displayNameSignal] reduce:^id(NSString* identifierValue, NSString* displayNameValue){      
    return @([identifierValue length] > 0 && [displayNameValue length] > 0);
}];

The error that I get is:

Cannot initialize a parameter of type 'id(^)()' with an rvalue of type 'id(^)(NSString* __strong, NSString* __strong)'

enter image description here

According to the documentation of ReactiveCocoa, I'm supposed to have a number of params for each signal in the combine block, but it does not seem to work.

And I have no idea why this thing expects a reduce block with no parameters...

Have anyone encountered this problem before?

https://github.com/ReactiveCocoa/ReactiveCocoa/blob/master/Documentation/BasicOperators.md#combining-latest-values


Solution

  • I know it looks horrible, but as I'm using Objective-C++ this thing goes crazy.

    I solve this thing by casting it to id and it works... don't ask me why.

    RACSignal* contactIdentifierSignal = RACObserve(self, contactIdentifier);
    RACSignal* displayNameSignal = RACObserve(self, displayName);
    
    RACSignal* mappedThing = [RACSignal combineLatest:@[contactIdentifierSignal, displayNameSignal] reduce:(id)^id(NSString* identifierValue, NSString* displayNameValue){      
        return @([identifierValue length] > 0 && [displayNameValue length] > 0);
    }];