In Objective-C we can call componentsJoinedByString
to produce a string with each element of the array separated by the supplied string. While Swift has a componentsSeparatedByString
method on String, there doesn't appear to be the inverse of this on Array:
'Array<String>' does not have a member named 'componentsJoinedByString'
What is the inverse of componentsSeparatedByString
in Swift?
The componentsJoinedByString is still available on NSArray, but not on Swift Arrays. You can bridge back and forth though.
Swift 3.0:
Similar to Swift 2.0, but API renaming has renamed
joinWithSeparator
tojoined(separator:)
.See Sequence.join(separator:) for more information.
Swift 2.0:
You can use the
joinWithSeparator
method onSequenceType
to join an array of strings with a string separator.See SequenceType.joinWithSeparator(_:) for more information.
Swift 1.0:
You can use the
join
standard library function onString
to join an array of strings with a string.Or if you'd rather, you can use the global standard library function: