Swift,数组
1、创建(Array)数组(数组内的类型一定要相同,有序的可重复)
(1)创建默认值的数组
let array:[Int] array=[Int](repeatElement(3,count:5)) //[3,3,3,3,3]
(2)创建有序范围Int的数组
let array=Array(0..<5) //[0,1,2,3,4] let array=Array(1...5) //[1,2,3,4,5]
(3)字面量创建数组(最常用)
let array=[1,2,3,4,5] //[1,2,3,4,5]
(4)空数组
var array=Array<Int>() //[]
2、查看数组的长度(count)和判断数组是否为空(isEmpty)
let array=[1,2,3,4,5] print(array.count) //5 array.isEmpty //false
3、数组(append)最后插入
let array=["a","b"] array.append("c") //["a","b","c"]
4、数组(insert)中间插入
let array=["a","b"] array.insert("c",at:1) //["a","c","b"]
5、根据数组索引(remove)删除
let array=["a","b"] array.remove(at:1) //["b"]