swift3新路程(4)数组和字典(array/dictionary)

前端之家收集整理的这篇文章主要介绍了swift3新路程(4)数组和字典(array/dictionary)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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 = [:]

猜你在找的Swift相关文章