关于 nil和“nil”的不同
(1)var optionalName: String? = nil
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \(name)"
}
else
{
greeting = "Hello, xiaoniao"
}
print(greeting)
print(" \n")
输出的结果是 Hello, xiaoniao
(2)var optionalName: String? = “nil”
var greeting = "Hello!"
if let name = optionalName {
greeting = "Hello, \(name)"
}
else
{
greeting = "Hello, xiaoniao"
}
print(greeting)
print(" \n")
输出的结果是 Hello, nil,此时optionalName的值为字符串“nil”