Instance Method

append(_:)

Adds an element to the end of the collection.

Declaration

mutating func append(_ newElement: UInt8)

Parameters

newElement

The element to append to the collection.

Discussion

If the collection does not have sufficient capacity for another element, additional storage is allocated before appending newElement. The following example adds a new number to an array of integers:

var numbers = [1, 2, 3, 4, 5]
numbers.append(100)

print(numbers)
// Prints "[1, 2, 3, 4, 5, 100]"

Complexity: O(1) on average, over many calls to append(_:) on the same collection.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software