[英]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. 我尝试创建ReactiveCocoa 3的Action<AnyObject?, Bool, NSError>
的实例。
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>'
. 此代码无法编译错误'SignalProducer<Bool, NoError>' is not convertible to 'SignalProducer<Bool, NSError>'
。
How can I convert SignalProducer<Bool, NoError>
to SignalProducer<Bool, NSError>
? 如何将SignalProducer<Bool, NoError>
转换为SignalProducer<Bool, NSError>
?
You can use the mapError
operator. 您可以使用mapError
运算符。 Something along the lines of: 有点像:
self.fooSignalProducer |> mapError { _ in NSError() }
Edit: 编辑:
As Justin points out below, promoteErrors
is specifically designed for this case: 正如Justin在下面指出的那样, promoteErrors
是专为此案例设计的:
self.fooSignalProducer |> promoteErrors(NSError)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.