Character Array from String in Swift 4

This question is simple. I need to get an array of a String's characters without using .characters (since it's deprecated)


For example, I want to turn


"Hello"


into


["H", "e", "l", "l", "o"]

Accepted Reply

let st = "Hello"

let stArray = Array(st)

print(stArray)

Replies

let st = "Hello"

let stArray = Array(st)

print(stArray)

> This question is simple


It’s really not. Claude’s answer probably works fine in most cases, but there are some odd definitions of what is a “character” (grapheme cluster) when it comes to Unicode and Emoji. This has changed over time in different Swift versions. Might be something to keep in the back of your mind. For example stackoverflow.com/questions/26862282/swift-countelements-return-incorrect-value-when-count-flag-emoji