Search code examples
iosreactive-cocoa

Combining RAC Signals and receive all values


I'm trying to get familiar with Reactive Cocoa, and running into a issue when combining signals.

I understand combineLatest or zip will only send a value when all of the combined signals sent at least one value. But is it possible to combine signals and get a value if any of the signals send a value?

I have several signals that I would like to execute the same code when a value is sent, regardless if the other signals every sent a value or not. Am I approaching this the wrong way? or is this possible?

Thanks


Solution

  • How about this:

    RACSignal* a = ...
    RACSignal* b = ...
    
    RACSignal* combined = [[RACSignal 
        combineLatest:@[[a startWith:nil], [b startWith:nil]] 
        skip:1];
    

    Here startWith: makes sure that all signals fire once at the beginning, producing a combined [nil, nil] tuple (which will be skipped by skip:1). Then, if for example a sends @"foo", combined will send a tuple of [@"foo", nil].