Adds the elements of a sequence to the end of the array.
SDK
- Xcode 10.2+
Framework
- Swift Standard Library
Declaration
mutating func append<S>(contentsOf newElements: S) where Element == S.Element, S : Sequence
Parameters
newElements
The elements to append to the array.
Discussion
Use this method to append the elements of a sequence to the end of this array. This example appends the elements of a Range<Int>
instance to an array of integers.
var numbers = [1, 2, 3, 4, 5]
numbers.append(contentsOf: 10...15)
print(numbers)
// Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
Complexity: O(m) on average, where m is the length of new
, over many calls to append(contents
on the same array.