As with Swift 2, String does not match SequenceType . However, you can use the characters property on String . characters returns a String.CharacterView that matches the SequenceType and therefore can be repeated using a for loop:
let word = "Zebra" for i in word.characters { print(i) }
Alternatively, you can add the extension to String to match SequenceType :
extension String: SequenceType {} // Now you can use String in for loop again. for i in "Zebra" { print(i) }
Although, I'm sure Apple had a reason to remove the String matching SequenceType , and so the first option seems to be the best choice. It is interesting to study what is possible, though.
ABakerSmith Jun 10 '15 at 9:31 on 2015-06-10 21:31
source share