Andrew Paul Simmons Andrew Paul Simmons - 6 months ago 35
Swift Question

What's the best way to transform an Array of type Character to a String in Swift?

This question is specifically about converting an Array of type Character to a String. Converting an Array of Strings or numbers to a string is not the topic of discussion here.

In the following 2 lines, I would expect

to be set to "C,a,t!,


Which to me sounds at least homogeneous enough to think it would be reasonable to implement the joinWithSeparator method to support the Character type. So, does anyone have a good answer as to why they don't do that???

This may be an oversight in the design. This error occurs because there are two possible candidates for joinWithSeparator(_:). I suspect this ambiguity exists because of the way Swift can implicit interpret double quotes as either String or Character. In this context, it's ambiguous as to which to choose.

  1. The first candidate is joinWithSeparator(_: String) -> String. It does what you're looking for.

    If the separator is treated as a String, this candidate is picked, and the result would be: "C,a,t,!,