//定义字典
let dict1 = ["name" : "小小", "age" : "6", "height" : 1.88] as [String : Any]
var dict2 = [:] as [String:Any]
var dict3 = Dictionary<String,Any>()
//字典的基本操作(增删改查)
var dictM = Dictionary<String,Any>()
dictM["name"] = "小小"
dictM["age"] = 18
dictM["height"] = 1.88
dictM["phone"] = "+86 130xxxxxxxx"
//当字典里有插入的key 那么下面操作就会把原来的value值改掉
dictM["name"] = "小黑"
print(dictM)
dictM.removeValue(forKey: "name")
//dictM.removeAll()
//便利字典
for key in dictM.keys {
print(key)
}
for value in dictM.values {
print(value)
}
for (key,value) in dictM {
print(key)
print(value)
}
//合并字典
for (key,value) in dictM {
dict2[key] = value
}