How to capitalize each word in a string using Swift iOS

Is there a function to capitalize each word in a string or is this a manual process?

For e.g. "bob is tall" And I would like "Bob Is Tall"

Surely there is something and none of the Swift IOS answers I have found seemed to cover this.


Are you looking for capitalizedString

Discussion
A string with the first character in each word changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values.

and/or capitalizedStringWithLocale(_:)

Returns a capitalized representation of the receiver using the specified locale.

For strings presented to users, pass the current locale ([NSLocale currentLocale]). To use the system locale, pass nil.


Swift 3:

var lowercased = "hello there"

var stringCapitalized = lowercased.capitalized
//prints:  "Hello There"

Since iOS 9 a localised capitalization function is available as capitalised letters may differ in languages.

if #available(iOS 9.0, *) {
  "istanbul".localizedCapitalizedString
  // In Turkish: "İstanbul"
}