美文网首页
swift5.0 -- Dictionary集合

swift5.0 -- Dictionary集合

作者: marlonxlj | 来源:发表于2021-07-12 11:21 被阅读0次
var dict = ["a":"A","b":"B","c":"C"]
//修改值
dict.updateValue("swift", forKey: "a")

//删除
//dict.removeAll()
//dict.removeValue(forKey: "c")
//指定删除
//dict.remove(at: dict.index(dict.startIndex, offsetBy: 1))
//解包
if let value = dict["a"]
{
//    print(value)
}else{
    print("没有值")
}

//过滤
var newD = dict.filter { (key,value) -> Bool in
    if value == "B" {
        return false
    }else{
        return true
    }
}

//print(newD)

//遍历
for (key,value) in dict {
    print("key:"+key, "value:"+value)
}

相关文章

网友评论

      本文标题:swift5.0 -- Dictionary集合

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