简体   繁体   中英

Map a SignalProducer that contains an error to return a NoError

I am working with ReactiveSwift 3.x in an iOS project and have been unable to map over an error provided by one SignalProducer into a different one.

My NoError SignalProducer is:

func foo() -> SignalProducer<Void, NoError>

The function being called within foo() that I want to map is:

func bar() -> SignalProducer<Data, MyError>

I currently have the following:

func foo() -> SignalProducer<Void, NoError> {
    // Stuff happens here...
    return bar()
        .map({ _ -> Void in
            return ()
        })
        .mapError({ error -> NoError in
            print(error.localizedDescription)
            // I do not want to handle this error
            return NoError
        })
}

But I am getting the error:

'mapError' produces 'SignalProducer< Void, F >', not the expected contextual result type 'SignalProducer< Void, NoError >'

Ultimately, I just want to print out the error, and then return.

Quack.

I had attempted some flatMapError work earlier, but got it to work with the following:

.flatMapError({ error -> SignalProducer<Void, NoError> in
    return SignalProducer.empty
    })

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