Swift 2.1,将字符串转换为[String](不是[Character]),怎么做?

时间:2015-10-29 16:15:00

标签: string swift2

我有一个字符串var a = "abcd",我希望获得一个单字符串["a", "b", "c", "d"]的数组。我试过了Array(a.characters),但这只给了我[Character]而不是[String]。怎么做?

1 个答案:

答案 0 :(得分:2)

var str = "abcd"
let strArr = str.characters.map { String($0) }