Generic Operator

+(_:_:)

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

Declaration

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

Parameters

lhs

A range-replaceable collection.

rhs

A collection or finite sequence.

Discussion

The two arguments must have the same Element type. For example, you can concatenate the elements of an integer array and a Range<Int> instance.

let numbers = [1, 2, 3, 4]
let moreNumbers = numbers + 5...10
print(moreNumbers)
// 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 two collections.

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

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