David DelMonte David DelMonte - 3 months ago 20
Swift Question

How do I get the length of a String in Swift3 on macOS

How do I get the length of a

String
in 'Swift3' on macOS?

This used to work in Swift2:

if purchaseDateString.length == 0 {
purchaseDateString = "n/a"
}


What is Swift3 equivalent for finding String's length.

UPDATE

There are answers to this question as Martin points out. The referred question has 30 answers. However, as far as I can tell, none of them relate specifically to Swift3. I could be wrong..

Answer

Have you try characters.count

if purchaseDateString.characters.count == 0 {
     purchaseDateString = "n/a"
}