gpt4 book ai didi

ios - 映射包含错误的 SignalProducer 以返回 NoError

转载 作者:行者123 更新时间:2023-11-30 11:19:54 25 4
gpt4 key购买 nike

我正在 iOS 项目中使用 ReactiveSwift 3.x,但无法将一个 SignalProducer 提供的错误映射到另一个错误。

我的NoError SignalProducer是:

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

我想要映射的 foo() 中调用的函数是:

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

我目前有以下内容:

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
})
}

但我收到错误:

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

最终,我只想打印出错误,然后返回。

最佳答案

嘎嘎。

我之前尝试过一些 flatMapError 工作,但让它与以下内容一起工作:

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

关于ios - 映射包含错误的 SignalProducer 以返回 NoError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51388685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com