frankakn_7 frankakn_7 - 5 months ago 9
iOS Question

How to determine word length in swift

let word : String = "hello"

var wordLength : Int = word.length //what to do here ?

for i in wordLength {
let index = word.startIndex.advancedBy(i)
print(word[index])
}


I want to print all the characters of the variable word individually, but i don't know how to determine when the word is over, or how often i have to loop until the whole word was printed.

Answer
let word = "hello"

for i in word.characters {
    print(i)
}