× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How do I convert a Swift Array to a String?

Antonio Bello
Mar 01, 2015
<p>If the array contains strings, you can use the <code>String</code>'s <code>join</code> method:</p> <pre><code>var array = ["1", "2", "3"] let stringRepresentation = "-".join(array) // "1-2-3" </code></pre> <p>This can be useful if you want to use a specific separator (hypen, blank, comma, etc).</p> <p>Otherwise you can simply use the <code>description</code> property, which returns a string representation of the array:</p> <pre><code>let stringRepresentation = [1, 2, 3].description // "[1, 2, 3]" </code></pre> <p>Hint: any object implementing the <code>Printable</code> protocol has a <code>description</code> property. If you adopt that protocol in your own classes/structs, you make them print friendly as well</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/25827033/How%20do%20I%20convert%20a%20Swift%20Array%20to%20a%20String?/25827087">Stack Overflow</a>.</p>
comments powered by Disqus