Trying to capitalize the first letter of each word in a text field Using Swift

Andy Lebowitz picture Andy Lebowitz · Jan 1, 2016 · Viewed 9.1k times · Source

I'm trying to capitalize the first letter of each word I put into a text field. I would like to put this code in here:

func textFieldShouldReturn(textField: UITextField) -> Bool {
//Here
}

My issue is that I have no idea what to put. I've tried creating a string like one post told me to do, and I'm having trouble:

nameOfString.replaceRange(nameOfString.startIndex...nameOfString.startIndex, with: String(nameOfString[nameOfString.startIndex]).capitalizedString)

I am not sure what to put inside that function to capitalize the first letter of each word.

Answer

technerd picture technerd · Jan 1, 2016

Simply set Textfield's Capitalization for words.

enter image description here