//创建字典的方法
var someDict = [Int:String]()
someDict.count
//定义一个key为字符串value也为字符串的字典
//这种的之所以没有按照顺序排列 因为不是数字的,是字符串的排列方式
var someDict1 : [String:String]=["1":"2222","2":"44444"]
someDict1
//访问字典的值
var DicValue1 = someDict1["2"]
//修改字典的值
var someDict2:[Int:String] = [1:"One", 2:"Two", 3:"Three"]
var oldVal = someDict2.updateValue("One 新的值", forKey: 1)
someDict2
someDict1["2"]="nihaoa"
someDict1
//移除字典的值
var removedValue = someDict2.removeValue(forKey:2)
someDict2
var removedValue1 = someDict1.removeValue(forKey: "1")
someDict1
//字典的增加
var addValue = someDict1.updateValue("33333", forKey: "4")
someDict1
//遍历字典
for (key,value) in someDict1
{
print(key+"==="+value)
}
for (key, value) in someDict2.enumerated()
{
print("键是\(key)=====值是\(value)")
}
//字典转数组
let keyArray = [String](someDict1.keys);
let valueArray = [String](someDict1.values);
//字典的长度
someDict2.count
//判断字典是否为空
let bool1 = someDict2.isEmpty
print(bool1)