swift5.0 -- Dictionary集合
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
网友评论