Generic Instance Method

joined(separator:)

Returns the concatenated elements of this sequence of sequences, inserting the given separator between each element.

Declaration

func joined<Separator>(separator: Separator) -> JoinedSequence<Range<Bound>> where Separator : Sequence, Separator.Element == Self.Element.Element
Available when Element conforms to Sequence.

Parameters

separator

A sequence to insert between each of this sequence’s elements.

Return Value

The joined sequence of elements.

Discussion

This example shows how an array of [Int] instances can be joined, using another [Int] instance as the separator:

let nestedNumbers = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
let joined = nestedNumbers.joined(separator: [-1, -2])
print(Array(joined))
// Prints "[1, 2, 3, -1, -2, 4, 5, 6, -1, -2, 7, 8, 9]"

See Also

Splitting and Joining Elements

func split(separator: Bound, maxSplits: Int, omittingEmptySubsequences: Bool) -> [Range<Bound>]

Returns the longest possible subsequences of the collection, in order, around elements equal to the given element.

func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Bound) -> Bool) -> [Range<Bound>]

Returns the longest possible subsequences of the collection, in order, that don’t contain elements satisfying the given predicate.

func joined() -> FlattenSequence<Range<Bound>>

Returns the elements of this sequence of sequences, concatenated.

func joined(separator: String) -> String

Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.

func joined(separator: String) -> String

Returns a new string by concatenating the elements of the sequence, adding the given separator between each element.