简体   繁体   中英

How can I convert “SignalProducer<Bool, NoError>” to “SignalProducer<Bool, NSError>” of ReactiveCocoa 3?

I tried creating an instance of Action<AnyObject?, Bool, NSError> of ReactiveCocoa 3.

let action: Action<AnyObject?, Bool, NSError> = Action { _ in
    if self.flag {
        return self.fooSignalProducer  // SignalProducer<Bool, NoError>
    } else {
        return self.barSignalProducer  // SignalProducer<Bool, NSError>
    }
}

This code isn't able to compile with error 'SignalProducer<Bool, NoError>' is not convertible to 'SignalProducer<Bool, NSError>' .

How can I convert SignalProducer<Bool, NoError> to SignalProducer<Bool, NSError> ?

You can use the mapError operator. Something along the lines of:

self.fooSignalProducer |> mapError { _ in NSError() }

Edit:

As Justin points out below, promoteErrors is specifically designed for this case:

self.fooSignalProducer |> promoteErrors(NSError)

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