美文网首页
swift开发中guard的用法

swift开发中guard的用法

作者: 专心致志的程序员 | 来源:发表于2019-06-07 09:57 被阅读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"])

相关文章

网友评论

      本文标题:swift开发中guard的用法

      本文链接:https://www.haomeiwen.com/subject/askmxctx.html