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
Signal
andSignalProducer
are.As described here, a
Signal
in ReactiveSwift is a hotRACSignal
in RAC 2.0 orObservable
in Rx, and aSignalProducer
in ReactiveSwift is a coldRACSignal
in RAC 2.0 orObservable
in 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
RACSignal
orObservable
since you want it to fire for every subscriber.So if you want to convert your RAC 2.0 code, that expects a cold
Signal
orObservable
, you will need to change it to take aSignalProducer
in 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
/value
Events they look more or less the same. Note, that you'll need tostart
the producer instead of justobserve
the 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
.SignalProducer
is equivalent to a coldSignal
which will fire for each subscriber.