通过阅读语言指南 (developer.apple.com) 学习 swift 3.1。我了解到在 swift 中赋值运算符 (=) 不返回值。在控制流章节中得到了一个保护语句的例子:
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).")
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果 '=' 运算符不返回值,则:
guard let name = person["name"] else {
return
}
Run Code Online (Sandbox Code Playgroud)
守卫如何确定name = person["name"]是真还是假,并根据它转到 else 并返回?