user130268
user130268

Reputation: 1361

Swift 2.1, convert string to [String] (not [Character]), how to do that?

I have a string var a = "abcd" and I want to get an array of one-character-string ["a", "b", "c", "d"]. I've tried Array(a.characters) but that only gives me [Character] not [String]. How to do that?

Upvotes: 0

Views: 59

Answers (1)

user3441734
user3441734

Reputation: 17534

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

Upvotes: 2

Related Questions