- Mastering macOS Programming
- Stuart Grimshaw
- 42字
- 2021-07-02 22:54:39
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]