Required Instance Methodswift 6.0.1Swift
append(_:)
Adds an element to the end of the collection.
mutating func append(_ newElement: Self.Element)
Parameters
- newElement
The element to append to the collection.
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]"
Other requirements
View members
Hide members
This section is hidden by default because it contains too many (17) members.
Type members
associatedtype SubSequence
init(
) Creates a new, empty collection.
init<S>(S
) Creates a new instance of a collection containing the elements of a sequence.
init(repeating: Self.Element, count: Int
) Creates a new collection containing the specified number of a single, repeated value.
Instance members
subscript(Range<Self.Index>
) -> Self.SubSequence subscript(Self.Index
) -> Self.Element func append<S>(contentsOf: S
) Adds the elements of a sequence or collection to the end of this collection.
func insert(Self.Element, at: Self.Index
) Inserts a new element into the collection at the specified position.
func insert<S>(contentsOf: S, at: Self.Index
) Inserts the elements of a sequence into the collection at the specified position.
func remove(at: Self.Index
) -> Self.Element Removes and returns the element at the specified position.
func removeAll(keepingCapacity: Bool
) Removes all elements from the collection.
func removeAll(where: (Self.Element) throws -> Bool
) rethrows Removes all the elements that satisfy the given predicate.
func removeFirst(
) -> Self.Element Removes and returns the first element of the collection.
func removeFirst(Int
) Removes the specified number of elements from the beginning of the collection.
func removeSubrange(Range<Self.Index>
) Removes the specified subrange of elements from the collection.
func replaceSubrange<C>(Range<Self.Index>, with: C
) Replaces the specified subrange of elements with the given collection.
func reserveCapacity(Int
) Prepares the collection to store the specified number of elements, when doing so is appropriate for the underlying type.
Citizens in Swift
Default implementations
func append(Self.Element
) Adds an element to the end of the collection.