On the playground, if you go to the menu "View"> "Debug area"> "Show debug area", you will see a complete error in the console:
/var/folders/2q/1tmskxd92m94__097w5kgxbr0000gn/T/./lldb/94138/playground29.swift: 5: 14: error: "indexes" are not available: access to the "indexes" property in the collection for the index in indexes (greeting)
Also, String no longer matches SequenceType , but you can access their elements by calling characters .
So, the solution for Swift 2 should do it like this:
let greeting = "Guten Tag" for index in greeting.characters.indices { print(greeting[index]) }
Result:
G
at
t
e
n
T
g
Of course, I assume your example is just to check indices , but otherwise you could just do:
for letter in greeting.characters { print(letter) }
source share