Generic Operator

+(_:_:)

Creates a new collection by concatenating the elements of two collections.

Declaration

static func + <Other>(lhs: Array<Element>, rhs: Other) -> Array<Element> where Other : RangeReplaceableCollection, Self.Element == Other.Element

Parameters

lhs

A range-replaceable collection.

rhs

Another range-replaceable collection.

Discussion

The two arguments must have the same Element type. For example, you can concatenate the elements of two integer arrays.

let lowerNumbers = [1, 2, 3, 4]
let higherNumbers: ContiguousArray = [5, 6, 7, 8, 9, 10]
let allNumbers = lowerNumbers + higherNumbers
print(allNumbers)
// Prints "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]"

The resulting collection has the type of the argument on the left-hand side. In the example above, moreNumbers has the same type as numbers, which is [Int].

See Also

Combining Arrays

func append<S>(contentsOf: S)

Adds the elements of a sequence to the end of the array.

func append<S>(contentsOf: S)

Adds the elements of a sequence or collection to the end of this collection.

static func + <Other>(Other, Array<Element>) -> Array<Element>

Creates a new collection by concatenating the elements of a sequence and a collection.

static func + <Other>(Array<Element>, Other) -> Array<Element>

Creates a new collection by concatenating the elements of a collection and a sequence.

static func += <Other>(inout Array<Element>, Other)

Appends the elements of a sequence to a range-replaceable collection.