//定义可选类型
//方式一
var name : Optional<String>
name = "why"
//解包
print("my name is " + name!)
//方式二 语法糖?
var phoneNum : String?
phoneNum = "+86 110"
print("my phone is " + phoneNum!)
//使用注意:如果可选类型为空而强行解包,会报错
//判断是否为空 第一种
if phoneNum != nil {
print("my phone is " + phoneNum!)
}
//第二种 可选绑定
// > 1.会强制解包,如果为空,跳过{} 2.如果有值,赋值给temp
if let temp = phoneNum {
print("my phone is " + temp)
}