var names = ["LiuMC","Ryoma"] var nameWithAge = ["LiuMC":27,"Ryoma":27] print(names) print(nameWithAge)
["LiuMC","Ryoma"]
["LiuMC": 27,"Ryoma": 27]
names是一个数组
nameWithAge是一个字典
创建空的数组和字典:
var emptyArray = [String]()
var emptyDictionary = [String:Int]()
如果类型可以推断的话 我们可以写成:
var emptyArray = []
var emptyDictionary = [:]
原文链接:https://www.f2er.com/swift/322976.html