Adds the elements of a sequence or collection to the end of this collection.
SDKs
- iOS 7.0+
- macOS 10.9+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
- Xcode 10.2+
Framework
- Foundation
Declaration
mutating func append<S>(contentsOf newElements: S) where S : Sequence, Self.Element == S.Element
Parameters
newElements
The elements to append to the collection.
Discussion
The collection being appended to allocates any additional necessary storage to hold the new elements.
The following 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), where m is the length of new
.