Swift2:从字典中提取值的正确方法
是否有一种更干净/更紧凑的方法可以使用默认值从字典中提取值Swift2:从字典中提取值的正确方法,swift2,Swift2,是否有一种更干净/更紧凑的方法可以使用默认值从字典中提取值 var desc = "" if let d = dict["error_description"] as? String { desc = d } 谢谢合并运算符??如果可选项不是nil则将其展开,否则将分配空字符串 let desc = (dict["error_description"] as?
var desc = ""
if let d = dict["error_description"] as? String {
desc = d
}
谢谢合并运算符
??
如果可选项不是nil
则将其展开,否则将分配空字符串
let desc = (dict["error_description"] as? String) ?? ""