在下面的代码行中,anotherVariable
恒定隐式地从右侧继承String
类型,而不是String?
为什么常量会继承“String?”键入而不是“字符串?”
var variable: String? = "hello"
if let anotherVariable = variable { // Unwrapping
// "anotherVariable" constant has a String type and its value is "hello"
}
你的问题是什么?你问为什么变量'example'是'String?'而不是'String'? –