swift开发中guard的用法

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"])

你可能感兴趣的:(swift开发中guard的用法)