//隐式
//var dic = ["name":"xiaoming","sName":"xiaoxiaoming","age":18] as [String:Any]
var dic:[String:Any] = ["name":"xiaoming","sName":"xiaoxiaoming","age":18]
//创建可变空字典
var dic2:[String:Any] = [:]
var dic3 = [String:Any]()
//字典遍历
for key in dic.keys {
print(key)
}
for value in dic.values {
print(value)
}
//同时获取key和value
for (k,v) in dic {
print("\(k)=\(v)")
}
//获取数据
var name = dic["name"]
dic.count
//插入数据
dic["x"] = "xx"
//修改数据
dic["x"] = "y"
dic.updateValue("m", forKey: "x")
dic
//元组 类似结构体
var myPoint = (18,20)
var message = (404,"Not Found")
//显式声明
var myPoint3D:(Float,Float,Float) = (1.3,2.4,2.1)
//获取元组中分量的值
myPoint.0
myPoint.1
//给分量命名
var newPoint = (x:18, y:20)
newPoint.x
newPoint.y
var httpResponse = (statusCode:200,message:"Success!")
httpResponse.message
httpResponse.statusCode
httpResponse.statusCode = 404
httpResponse
网友评论