1.字典声明
//泛型语法声明字典
var myDict : Dictionary<String, String>
//简化语法声明字典
var scores : [String:Int]
var health : [String:String]
2.字典初始化
//默认大小字典
myDict = Dictionary<String, String>()
//大小为5字典
scores = Dictionary<String, Int>(minimumCapacity:5)
print(scores)
//简化语法创建字典
health = ["身高":"172" , "体重":"75" , "血压":"86/113"]
print(health)
var dict = ["one": 1 , "two": 2 , "three": 3, "four": 4]
print(dict)
3.字典键与值操作
//简化语法创建空字典
var emptyDict:[String:Double] = [:]
print(emptyDict.isEmpty)
print(emptyDict)
var height = health["身高"]
print("身高为:\(height)")
//获取不存在key
var noExist = health["no"]
print(noExist)
//修改key对应Value
health["血压