我想连接一个字符串,我这样做:
var text: String!
....
text = "hello"
text += "! How r you?"
但我收到以下错误:
无法转换“字符串!”类型的值 到预期的参数类型 'inout String' text += "!" ^~~~
我该如何解决?谢谢
在您的情况下,将值声明为空是没有意义的,因为您正在下一行修改它。
但是,如果分配发生在其他地方并且您想使用 变量!
,则应检查字符串是否具有 值?
。如果text
是,则不会调用此方法nil
。
text? += "! How r you?"
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句