When updating the text of UITextView, I found textView.text += "..."
does not work. The compiler warned me that "Binary operator '+=' cannot be applied to operands of type 'String!' and 'String'". It seems that I must append an exclamatory mark after textView.text
.
However, if I expanded it to textView.text = textView.text + "..."
, it worked. I wonder whether it is designed as this or I misunderstood something?
Implicitly unwrapped optional is still an Optional
and it's different from type that it wraps. So you need to define operator:
func +=(inout l: String!, r: String) {
l = (l ?? "") + r
}
var a: String! = "a"
var b: String = "b"
a += b // "ab"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With