Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Mutating an array

Adding and inserting individual elements or several elements is performed as follows:

var arr = [2, 3, 5, 7] 
arr.append(11)

let tens = [10, 20, 30]
arr.append(contentsOf: tens)

arr.insert(13, at: 5)
arr.insert(40, at: arr.endIndex)
arr[6...8] = [17, 19, 23]