//: Playground - noun: a place where people can play
import UIKit
//声明、定义数组
var numbers = [1, 2,216)">3,216)"> 5,216)">8]
var strings = ["ios","android","java"]
//数组长度
numbers.count
strings.count
//向数组中添加元素
//向数组中追加元素
numbers.append(13)
strings.append("javascript")
//直接向数组后面添加一个数组
numbers += [21,216)">34]
strings += ["jquery","C#"]
//使用index索引添加元素
numbers.insert(-0)
strings.insert("apple",216)">0)
//删除数组中得元素
numbers.removeAtIndex(0)
numbers
strings.removeAtIndex( strings
//删除数组中最后一个元素
numbers.removeLast()
strings.removeLast()
strings
//使用enumerate
for (index,item) in enumerate(numbers) {
println("\(index):\(item)")
}
for item in enumerate(strings) {
println("index:\(item.0),值:\(item.1)")
}
//创建数组
var nums = [Int]()
class Admin {
}
var student = [Admin]()
//创建指定大小数组
var num2 = [Int](count: 5,repeatedValue: 3)
//数组的赋值和拷贝行为
var num3 = [2,216)"> 3,216)">4,216)"> 5]
var num4 = num3
num3[1] = 100
num3
num4
//
var num5 = num3
原文链接:https://www.f2er.com/swift/326786.html