swiftreactive-cocoareactive-swiftreactive-cocoa-5

How to turn a Property<Int> into a SignalProducer<Int, PossibleError>?


Given

let numberOfSneezes = Property<Int>(0)

how do i turn numberOfSneezes.producer into this type of producer

let sneezeNumberProducer: SignalProducer<Int, PossibleError>

?

I know numberOfSneezes.producer is not going to send any errors, but i need to assign it to sneezeNumberProducer anyway.


Solution

  • You can use promoteError(). Here is the documentation for it.

    sneezeNumberProducer = numberOfSneezes.producer.promoteError(PossibleError.self)