0
使用ReactiveSwift,我使用以下代碼:'String'不能轉換爲'String?'
let alertMessageProperty = MutableProperty<String?>(nil)
...
.on(failed: { self.alertMessageProperty.value = $0.localizedDescription })
...
這意味着:
self.alertMessageProperty.value
是String?
- 在
.on(failed:)
類型,failed
是((Error) -> Void)?
類型,以便$0
的類型爲錯誤和$0.localizedDescription
類型爲String
。 - 在一個簡單的Playground中,將
String
分配給String?
變量的工作正常,如預期的那樣。
它不編譯,我得到這個錯誤:
'String' is not convertible to 'String?'
我覺得String
是SO轉換爲String?
。這裏發生了什麼?
版本:斯威夫特3.2 - ReactiveSwift 2.0.1
一個是可選的,一個不是。 – LinusGeffarth
可能重複的[錯誤:'字符串'不能轉換爲'字符串!'](https://stackoverflow.com/questions/38186121/error-string-is-not-convertible-to-string) – alseether
@alseether:有趣的,但在這個職位的答案不明確。這聽起來像是一個Swift編譯器錯誤,但它沒有明確提及。 –