Alternatively, to get valid characters, you can call:
let characters = Array(string)
Then you can simply call:
let length = characters.count
However, you can also just use the count function if you don't need to iterate over characters or anything in Swift 1.2:
let length = count(string)
In Swift 2:
let length = string.count()
source share