Available Now: Test-Driven Development in Swift with SwiftUI and Combine

mokacoding

unit and acceptance testing, automation, productivity
Archive Tags About Subscribe

Swift array of characters from String

Wed Aug 12 2015 -Swift -Espresso

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

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

To do so you can do:

"foo bar".map { String(0ドル) }

or if you are into point free notation:

"foo bar".map(String.init)

There you go. 😎


For the record, this post dates back to Swift version 2. If you're into programming language archeology, checkout the original version here.

Want more of these posts?

Subscribe to receive new posts in your inbox.

Please enable JavaScript to view thecomments powered by Disqus.

mokacoding

Hi I'm Gio I write here semi-regularly on software testing and TDD, productivity, and iOS development.

Get in touch if you're interested in working together.

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /