func greet(person: [String: String]) {
guard let name = person["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": "John"])
// 출력
// Hello John!
// 두 번째 guard문은 location 값이 없어 조건이 false가 되고 따라서 else절이 실행된다.
// I hope the weather is nice near you.
greet(person: ["name": "John", "location": "Cupertino"])
// 출력
// Hello John!
// I hope the weather is nice in Cupertino