Mr.KLD Mr.KLD - 4 months ago 15
iOS Question

Convert Swift string to array

How can I convert a string "Hello" to an array ["H","e","l","l","o"] in Swift?

In Objective-C I have used this:

NSMutableArray *characters = [[NSMutableArray alloc] initWithCapacity:[myString length]];
for (int i=0; i < [myString length]; i++) {
NSString *ichar = [NSString stringWithFormat:@"%c", [myString characterAtIndex:i]];
[characters addObject:ichar];


It is even easier in Swift:

let string : String = "Hello