1 //用if let与guard let实现同一效果,会发现guard降低一个分支 2 //可以用if var guard var 表示定义的变量能修改值 3 func test(){ 4 let name:String? = "张三" 5 6 if let a = name { 7 print(a) 8 }else{ 9 print("李四")10 }11 12 guard let c = name else {13 print("李四")14 return15 }16 print("c=\(c)")17 18 }19 test()