May 27, 2020

soltveit.org

..Geekish..

Swift Capitalize words, How to

Swift Capitalize

Swift Capitalize, How to

Swift Capitalize is done with a string instance property. Check the example below to see how to use it. There is also a link at bottom to Apples Swift documentation.
let str = “first, second, third”
print(str.capitalized)

This will output: First, Second, Third

Swift Capitalize

It will capitalize every word in this string. Lets remove the commas and see what happens.

Change str = “first second third”

The output now will be: First Second Third

Check Apple Swift Capitalizion documentation for more information about the string instance property.

Swift Capitalizion
Produce a string with the first character from each word changed to the corresponding uppercase value.