Instance Method

joined(separator:)

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

Declaration

func joined(separator: String = default) -> String

Parameters

separator

A string to insert between each of the elements in this sequence. The default separator is an empty string.

Return Value

A single, concatenated string.

Discussion

The following example shows how an array of strings can be joined to a single, comma-separated string:

let cast = ["Vivien", "Marlon", "Kim", "Karl"]
let list = cast.joined(separator: ", ")
print(list)
// Prints "Vivien, Marlon, Kim, Karl"

See Also

Splitting and Joining Elements

func split(separator: Self.Element, maxSplits: Int, omittingEmptySubsequences: Bool)

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

func split(maxSplits: Int, omittingEmptySubsequences: Bool, whereSeparator: (Self.Element) -> Bool)

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

Required. Default implementations provided.

func joined()

Returns the elements of this sequence of sequences, concatenated.

func joined<Separator>(separator: Separator)

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