ios - '() -> 绑定目标' 不能转换为 '(Bool) -> BindingTarget'
问题描述
我最近继承了一个使用 ReactiveSwift 3.1.0 和 ReactiveCocoa 7.2.0 编写的 iOS 项目。我的任务是将它更新到 Swift 5 和最新的 ReactiveSwift 版本。
我将 ReactiveSwift 更新到 6.1.0,将 ReactiveCocoa 更新到 10.1.0。我不精通反应式编程,但我设法将现有代码库的很大一部分转换为最新版本。
但是我被困在这个特定的部分。原来的程序员不再可用。
在这个项目中,视图控制器上有一个扩展来显示错误消息。
extension Reactive where Base: UIViewController {
func presentError(animated: Bool = true) -> BindingTarget<Error> {
return self.makeBindingTarget { $0.present(error: $1, animated: animated) }
}
func present(error: Error, animated: Bool = true, completion: (() -> Void)? = nil) {
LogError("Presenting error: \(error.verboseDescription)")
self.present(UIAlertController(error: error, completion: completion), animated: animated, completion: nil)
}
}
在视图控制器中,我在这一行收到以下错误。
self.reactive.presentError() <~ self.viewModel.reportAction.errors.map { $0 }
'() -> BindingTarget' 不能转换为 '(Bool) -> BindingTarget'
这是视图模型中的相关部分。
private(set) var reportAction: Action<(User, ReportReason), Void, APIKit.Error>!
这里发生的唯一变化是errors
类型从viewModel.reportAction.errors.map { $0 }
更改public let errors: Signal<Error, NoError>
为public let errors: Signal<Error, Never>
。这是由于在最新的 ReactiveSwift 源代码中进行了一些更改。
这显然破坏了这段代码。我不确定为什么会发生错误以及如何修复这部分。
解决方案
推荐阅读
- python - 在 Bash/Python 中转换 CIM_DATETIME
- python - python3大json解析keyerror
- javascript - VUEJS中通知函数的全局调用
- javascript - 内容溢出溢出 div 视图高度
- postgresql - PostgreSQL - 授权的附加外键约束
- reactjs - 将枚举中的 {{}} 替换为 react 中来自 api 的数据
- key - 我可以在 Dynamodb 中为分区键和唯一排序键使用常量吗?
- rest - RabbitMQ 事件订阅者 - 哪个好?Windows 服务或 Http 服务 (REST API)
- spring-boot - Thymeleaf 中的 @{..} 表达式是什么
- javascript - 计算字符串中的单词出现次数 javascript