Julius Julius - 2 years ago 145
Swift Question

String length Swift

Something that has been driving me crazy is finding a simple thing: String length in Swift.

No, you cannot use string.length

No, you cannot use string.characters.count

No, you cannot use string.count

The only thing that works for me is string.endIndex. That however does not work for a simple textField check, e.g.

func textViewDidChange(textView: UITextView) {
if textView.text.endIndex > 20 {
setBorder(descriptionField, finished: true)
} else {
setBorder(descriptionField, finished: false)

Since endIndex is not an Int and cannot be converted into in. This whole thing is driving me crazy, I don't know what to do. Any help would be appreciated!

Answer Source

Just use count()


in swift 2.0 some of the stuff you mentioned works =]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download