Required Instance Methodswift 6.0.1Swift
reserveCapacity(_:)
Prepares the collection to store the specified number of elements, when doing so is appropriate for the underlying type.
mutating func reserveCapacity(_ n: Int)
Parameters
- n
The requested number of elements to store.
If you are adding a known number of elements to a collection, use this method to avoid multiple reallocations. A type that conforms to RangeReplaceableCollection
can choose how to respond when this method is called. Depending on the type, it may make sense to allocate more or less storage than requested, or to take no action at all.
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(Self.Element
) Adds an element to the end of the collection.
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.
Citizens in Swift
Default implementations
func reserveCapacity(Int
) Prepares the collection to store the specified number of elements, when doing so is appropriate for the underlying type.