先看下面的代码
// 如果name和age一个为空则返回nil func Person(name: String?,age: Int?) ->Bool { if name != nil { if age != nil { return true }else { return false } }else { return false } } func Person1(name: String?,age: Int?) ->Bool { guard name != nil else { return false } guard age != nil else { return false } return true } func Person2(name: String?,age: Int?) ->Bool { guard (name != nil),(age != nil) else { return false } return true } var is0 = Person(name: "gaobo",age: nil) var is1 = Person1(name: "gaobo",age: nil) var is2 = Person(name: "gaobo",age: 18)原文链接:https://www.f2er.com/swift/322159.html