简体   繁体   中英

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

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] .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM