答案 0 :(得分:2)
像这样使用
let name = "\(firstName!) \(lastName)"
我也试过基本的例子。如果字符串包含可选(“”),则可以通过强制编译器隐式强制解包来解决此问题。
你可以登记.playground
let firstname : String!
let lastname : String!
firstname = "Hello" ==> "Hello"
lastname = "World" ==> "World"
let fullname = "\(firstname) \(lastname)" ==> "Optional("Hello") Optional("World")"
let fullname = "\(firstname!) \(lastname!)" ==> "Hello World"
尝试使用上述解决方案,希望它有帮助!