Operatorswift 6.0.1Swift
+=(_:_:)
Appends the elements of a sequence to a range-replaceable collection.
static func += <Other>(lhs: inout Self, rhs: Other) where Other : Sequence, Self.Element == Other.Element
Parameters
Use this operator to append the elements of a sequence to the end of range-replaceable collection with same Element
type. This example appends the elements of a Range<Int>
instance to an array of integers.
var numbers = [1, 2, 3, 4, 5]
numbers += 10...15
print(numbers)
// Prints "[1, 2, 3, 4, 5, 10, 11, 12, 13, 14, 15]"
Other members in extension
Type members
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.
static func + <Other>(lhs: Other, rhs: Self
) -> Self Creates a new collection by concatenating the elements of a sequence and a collection.
static func + <Other>(lhs: Self, rhs: Other
) -> Self Creates a new collection by concatenating the elements of a collection and a sequence.
static func + <Other>(lhs: Self, rhs: Other
) -> Self Creates a new collection by concatenating the elements of two collections.
Instance members
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 applying(CollectionDifference<Self.Element>
) -> Self? Applies the given difference to this collection.
func filter((Self.Element) throws -> Bool
) rethrows -> Self Returns a new collection of the same type containing, in order, the elements of the original collection that satisfy the given predicate.
func insert(Self.Element, at: Self.Index
) Inserts a new element into the collection at the specified position.
func insert<C>(contentsOf: C, 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 elements in the specified subrange from the collection.
func removeSubrange<R>(R
) Removes the elements in the specified subrange from the collection.
func removeSubranges(RangeSet<Self.Index>
) Removes the elements at the given indices.
func replaceSubrange<C, R>(R, 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.