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 Foundation
import Foundation
// create some strings
let name = "theodore"
let language = "swift"
let greeting = "edpresso is the best!"
// use the capitalized property
print(name.capitalized) // Theodore
print(language.capitalized) // Swift
print(greeting.capitalized) // Edpresso Is The Best!

Code explanation

  • Line 2: We import the Foundation framework. This framework allows us to access some properties and methods of the string and other data types. We need it to access the capitalized property.
  • 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 ©2025 Educative, Inc. All rights reserved