I need to convert a string into an array of characters. This work in Swift 1.2 and lower but doesn't since Swift 2.0
var myString = "Hello"
Array(myString) // ["H", "e", "l", "l", "o"]
To split a string into an array in Swift, use the String. split() function.
To convert an array to string in Swift, call Array. joined() function.
Swift String split() The split() method breaks up a string at the specified separator and returns an array of strings.
var myString = "Hello"
let characters = [Character](myString.characters) // ["H","e","l","l","o"]
Hope this helps
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