【发布时间】:2020-01-17 19:32:24
【问题描述】:
有没有办法强制字典返回一个非可选值? , 如果它不存在就断言
var dic = Dictionary<String,String>()
dic["0"] = "Zero"
let z = dic["0"] // is there a way that the 'z' variable will not be an optional (without doing an optional unwrapping, and so) , and if the value don't exists the program will assert
这种事情可以通过字典的扩展来实现吗?
【问题讨论】:
-
你的意思是this?
-
使用
guard有什么问题?
标签: swift xcode dictionary