ReactiveCocoa: [RACSignal combineLatest:reduce:] won't compile as Objective-C++

If I have my implementation file type set to “Objective-C++ Source” I get a compiler error like

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

when attempting to compile something like

RAC(self.submitButton, enabled) = [RACSignal 
  combineLatest:@[siteAddressValidSignal, accessKeyValidSignal] 
  reduce:^id(NSNumber *siteAddressValid, NSNumber *accessKeyValid){
    return @(siteAddressValid.boolValue && accessKeyValid.boolValue);
}];

If I change the file type to Objective-C, it compiles fine.

About this issue

  • Original URL
  • State: closed
  • Created 11 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

Thanks for providing the sample project, it helped me a lot.

Turns out the easiest way to deal with this issue is to cast the block to id, sidestepping the type checking entirely:

RAC(self.submitButton, enabled) = [RACSignal
    combineLatest:@[siteAddressValidSignal, accessKeyValidSignal]
    reduce:(id)^id(NSNumber *siteAddressValid, NSNumber *accessKeyValid){
        return @(siteAddressValid.boolValue && accessKeyValid.boolValue);
    }];

The code compiled without issues once I reverted the changes to RAC and the sample program seems to work fine.