使用 ReactiveSwift,我使用了以下代码:
let alertMessageProperty = MutableProperty<String?>(nil)
...
.on(failed: { self.alertMessageProperty.value = $0.localizedDescription })
...
意思是:
self.alertMessageProperty.value是类型String?- in
.on(failed:),failed是类型((Error) -> Void)?所以$0是类型 Error 并且$0.localizedDescription是类型String。 - 在一个简单的 Playground 中,将 a 分配
String给一个String?变量可以正常工作,正如预期的那样。
它无法编译,我收到此错误:
'String' is not convertible to 'String?'
我认为String可以转换为String?. 这里发生了什么?
版本:Swift 3.2 - ReactiveSwift 2.0.1