1、创建(Dictionary)字典(无序的可重复)
(1)指定类型
var a:Dictionary=["a":"b"]
(2)简单版指定类型
var b:[String:String]=["a":"w"]
(3)字面量创建(常用)
var b=["a":"w"]
2、添加、修改、删除
(1)添加
var a=["a":"a"]a["b"]="b" //["a": "a", "b": "b"]
(2)修改
var a=["a":"a"]a["a"]="b" //["a": "b"]
(3)删除
var a=["a":"a"]a["a"]=nilprint(a.isEmpty) //true
3、循环
(1)for循环键值对
var a=["a":"b"]for (key,value) in a{ print(key,value) //a b}
(2)for循环键
var a=["a":"b"]for key in a.keys{ print(key) //a}
(3)for循环值
var a=["a":"b"]for value in a.values{ print(value) //b}
4、分离成数组
(1)分离键
var a=["a":"b"]var b=[String](a.keys) //["a"]
(2)分离值
var a=["a":"b"]var b=[String](a.values) //["b"]