Required Initializerswift 6.0.1Swift
init(_:)
Creates a new instance of a collection containing the elements of a sequence.
init<S>(_ elements: S) where S : Sequence, Self.Element == S.Element
Parameters
- elements
The sequence of elements for the new collection.
elements
must be finite.
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(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.
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
init<S>(S
) Creates a new instance of a collection containing the elements of a sequence.
Available in Cxx
Default implementations
init<C>(C
) Creates a collection containing the elements of a C++ container.
Extension in AsyncAlgorithms
Default implementations
init<Source>(Source
) async rethrows Creates a new instance of a collection containing the elements of an asynchronous sequence.