I have an array of strings in swift and I thought I could do:
array.join(",")
to return a comma separated list of the elements
The error I'm getting is: Array<String> not convertible to 'String'
How can I do this correctly in as little code as possible.
I can do it with a loop to build a string but I thought there was a simpler way to do this.
Given an array of strings:
var x = ["one", "two", "three"]
the correct syntax to join strings is:
",".join(x)
x.joinWithSeparator(",")
In Swift 2,
array.joinWithSeparator(",")
In Swift 4
let array:[String] = ["one", "two","three"]
array.joined(separator: " ")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With