swift开发中guard的用法

2019-06-07  本文已影响0人  专心致志的程序员
func greet (person:[String: String]){

    guard let name = person["name"] else{
        return
    }

    if let name = person["name"] {
        print(name)
    }else{
        return
    }

    print("hello \(name)!")
    guard let location = person["location"] else {
        print("I hope the weather is nice near you .")
        return
    }
    print("I hope the weather is nice in \(location)")
}


//greet(person: ["name":"ryan"])

greet(person: ["location":"ChongQing"])

//greet(person: ["name":"ryan","location":"Cupertion"])
上一篇 下一篇

猜你喜欢

热点阅读