What is the capitalized property in Swift?
Overview
The capitalized property of a string in Swift returns the same string with the first character from each word, in the string, changed to its corresponding uppercase value. All remaining characters of the string are set to their corresponding lowercase values.
Syntax
string.capitalized
Return value
This property returns a string with the first character of each word, in the string, changed to its corresponding uppercase value and all remaining characters set to their corresponding lowercase values.
Code example
// import Foundationimport Foundation// create some stringslet name = "theodore"let language = "swift"let greeting = "edpresso is the best!"// use the capitalized propertyprint(name.capitalized) // Theodoreprint(language.capitalized) // Swiftprint(greeting.capitalized) // Edpresso Is The Best!
Code explanation
- Line 2: We import the
Foundationframework. This framework allows us to access some properties and methods of the string and other data types. We need it to access thecapitalizedproperty. - Lines 5–7: We create some string values.
- Lines 10–12: We get the corresponding uppercase values of the characters in the strings. And then, we print the results to the console.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved