What is the localizedCapitalized property in Swift?
Overview
In Swift, the localizedCapitalized property returns the capitalized representation of a string instance that is produced using the current locale.
Syntax
string.localizedCapitalized
Return Value
This property returns a capitalized representation of a string using the current locale.
Example
// import the foundation frameworkimport Foundation// create stringslet str1 = "google"let str2 = "netflix"let str3 = "amazon"let str4 = "apple"let str5 = "meta"// get the capitalized representationprint(str1.localizedCapitalized)print(str2.localizedCapitalized)print(str3.localizedCapitalized)print(str4.localizedCapitalized)print(str5.localizedCapitalized)
Explanation
- Line 2: We import the
Foundationframework. This allows us to use thelocalizedCapitalizedproperty. - Lines 5–9: We create some strings.
- Lines 12–16: We use
localizedCapitalizedon the strings and print the output to the console.