String indices in Swift 2
In a Playground, if you go to menu View > Debug Area > Show debug area, you can see the full error in the console:
/var/folders/2q/1tmskxd92m94__097w5kgxbr0000gn/T/./lldb/94138/playground29.swift:5:14: error: 'indices' is unavailable: access the 'indices' property on the collection for index in indices(greeting)
Also, String
s do not conform to SequenceType
s anymore, but you can access their elements by calling characters
.
So the solution for Swift 2 is to do it like this:
let greeting = "Guten Tag"
for index in greeting.characters.indices {
print(greeting[index])
}
Result:
G
u
t
e
nT
a
g
Of course, I assume your example is just to test indices
, but otherwise you could just do:
for letter in greeting.characters {
print(letter)
}