I have the same problem as this post, Combine signals in ReactiveCocoa to a new one that fires when all change

So I changed to use zip: the the odd problem is the second signals data is not latest one. I put a log in the second signal's map code, it's the latest. E.g.

Signal A, Signal B

[self rac_liftSelector:@selector(doTask:) withSignals:[RACSignal zip:@[A, B]      
reduce^id(NSNumber* a, NSNumber* b){
   a// is updated to latest
   b// is the old value
}];

In Signal B, I put log found b value is updated. If I changed back to CombineLatest: b is updated but a is old value and the signal is not triggered.

有帮助吗?

解决方案

+[RACSignal zip:] doesn't always give you the latest value on each of the signals you pass into it. It gives you the next value from each signal. That means that if you have the following marble diagram:

Signal A | -(a0)-------------(a1)-----x
         |
Signal B | ----(b0)-(b1)-(b2)----(b3)--->
         |
 zip:A,B | ----(a0,b0)-------(a1,b1)--x
         |
         +-------------------------------
              -- Time -->

Your signal will be sent (a0, b0) when b0 is sent, then (a1, b1) when a1 is sent, and then no more values will be sent because Signal A completes after only two values.

+[RACSignal combineLatest:reduce:], on the other hand, will always give you the latest value on each of the signals you pass into it whenever either signal sends a value (after all signals have sent at least one value):

Signal A | -(a0)-----------------------(a1)-----x
         |
Signal B | ----(b0)----(b1)----(b2)------------(b3)---->
         |
cl/r:A,B | ----(a0,b0)-(a0,b1)-(a0,b2)-(a1,b2)-(a1,b3)->
         |
         +----------------------------------------------
              -- Time -->
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top