Try this:
Array(0...9).map({String($0)}).map({ Character($0) })
In the code above, we are taking each Int
from [Int]
, transform it into String
using the String constructor/initializer (in order words we're applying the String initializer (a function that takes something and returns a string) to your [Int]
using map
an higher order function), once the first operation is over we'd get [String]
, the second operation uses this new [String]
and transform it to [Character]
.
if you wish to read more on string visit here.
@LeoDabus proposes the following:
Array(0...9).map(String.init).map(Character.init) //<-- no need for closure
Or instead of having two operations just like we did earlier, you can do it with a single iteration.
Array(0...9).map({Character("\($0)")})
@Alexander proposes the following
Array((0...9).lazy.map{ String($0) }.map{ Character($0) })
(0...9).map{ Character(String($0)) } //<-- where you don't need an array, you'd use your range right away