guard 语句
解包之后b的作用域仍然有效
var a: String? = "lcm"
guard let b = a else { print("a is nil") }
print(b)
if 语句
解包之后b的只有在 { ... } 内才有作用域
var a: String? = "lcm"
if let b = a { print(b) }
解包之后b的作用域仍然有效
var a: String? = "lcm"
guard let b = a else { print("a is nil") }
print(b)
解包之后b的只有在 { ... } 内才有作用域
var a: String? = "lcm"
if let b = a { print(b) }
本文标题:guard 与 if 的区别
本文链接:https://www.haomeiwen.com/subject/dvjplxtx.html
网友评论