mokacoding

unit and acceptance testing, automation, productivity

Swift array of characters from String

Sometimes you might need to get an array of characters out of a String, for example:

"foo bar" => ["f", "o", "o", " ", "b", "a", "r"]

This used to be trivial in Swift 1.x, but became slightly more tedious in Swift 2:

"foo bar".characters.map { String($0) }

There you go. 😎

Vote on Hacker News