Swift数组

2018-06-26  本文已影响12人  iOS_July

一、数组的介绍

二、数组的初始化

let array : Array<String> = ["July","福尔摩洪"]
let array1 = ["July","福尔摩洪"]
var arrayM : [String] = Array()
var arrayM1 = Array<String>()
var arrayM2 = [String]()

三、对数组的基本操作

arrayM.append("July")
arrayM.append("is")
arrayM.append("handsome")
arrayM.remove(at: 0)
arrayM[0] = "福尔摩洪"
let item = arrayM[0]

四、数组的遍历

let count = arrayM.count
for i in 0..<count {
    print(arrayM[i])
}
for item in arrayM {
    print(item)
}
for (index, item) in arrayM.enumerated() {
    print(index)
    print(item)
}

五、数组的合并

let arrayH1 = ["July","handsome"]
let arrayH2 = ["福尔摩洪","handsome"]
let arrayH3 = arrayH1 + arrayH2
上一篇下一篇

猜你喜欢

热点阅读