字典操作
//创建字典
var dict : Dictionary = ["111":"aaa","22":"bb","ccc":"333"]
//字典添加或更新元素
dict.updateValue("chaofan", forKey: "333")
dict["333"] = "我是3"
dict["444"] = "ddd"
//移除对象
dict.removeValueForKey("22")
dict["333"] = nil
//移除字典所有的对象
dict.removeAll()
//创建不可变字典
let mutableDict :NSMutableDictionary = ["111":"aaa","22":"bb"]
//更改value
mutableDict["111"] = "chaofan"
//添加元素
mutableDict.setValue("ccc", forKeyPath: "333")
//删除元素
mutableDict.removeObjectForKey("22")
//取出元素
let value = mutableDict["111"]
print(value)
//字典总个数
print(mutableDict.count)
//字典遍历
for key in dict{
print(key)
}
for (key,value) in dict{
print("key is \(key) and value is \(value)")
}
for (key, _) in dict {
print(key)
}
for (_, value) in dict {
print(value)
}