With RxSwift, I would do Observable.just(1) which will emit 1 then emit completed.
It looks like with RAC2 you could do: [RACSignal return:@1]
How do I do that with RAC3?
To be more clear... I'm looking for a way to create a RAC3 Signal that produces a single hard-coded value. How would I do that? (SignalProducer(value: 1) doesn't work that way.)
After reading the discussion, I think the answer by Charlotte Tortorella stands correct: you achieve the required behavior with
SignalProducer(value: 1).I think the problem is a miss understanding about what
SignalandSignalProducerare.As described here, a
Signalin ReactiveSwift is a hotRACSignalin RAC 2.0 orObservablein Rx, and aSignalProducerin ReactiveSwift is a coldRACSignalin RAC 2.0 orObservablein Rx. This is deliberate deviation from other reactive frameworks as well as from RAC < 3.0.This means, you most likely have a method that takes a cold
RACSignalorObservablesince you want it to fire for every subscriber.So if you want to convert your RAC 2.0 code, that expects a cold
SignalorObservable, you will need to change it to take aSignalProducerin RAC >= 3.0.As an illustration take this example in ObjC and RAC 2.0:
Calling this method like this
(twice for illustration of the behaviour on each subscription) will print
In Swift and with ReactiveCocoa 5.0, an equivalent implementation could look like this
Called like this
it produces the same output
The swift version might look a bit bulkier, but if you only need the
Next/valueEvents they look more or less the same. Note, that you'll need tostartthe producer instead of justobservethe signal.So in conclusion:
You are correct, theres no way to provide an equivalent if you expect a
Signal. For an equivalent implementation, you will need to change your function to take aSignalProducer.SignalProduceris equivalent to a coldSignalwhich will fire for each subscriber.