How to convert Swift String to Array of String

by

To convert the string literal into an array of strings, we use the map function on the string literal.

map(_:)

Returns an array containing the results of mapping the given closure over the sequence’s elements.


let stringArray =  string.map { String($0) }

Inside the map function, we convert each character in the string literal to a string using the String($0) initializer.

The map function returns an array of strings, where each character is represented as a separate string element.



More Articles

Recommended posts