What is the localizedUppercase property of a String in Swift?

Overview

The localizedUppercase property of a String instance in Swift is used to get the uppercase version of a string that is produced using the current locale.

Syntax

string.localizedUppercase

Return value

This property returns the uppercase representation of the String instance string.

Example

Let’s look at the code below:

// import the foundation framework
import Foundation
// create strings
let str1 = "Metamask"
let str2 = "Solana"
let str3 = "NFT"
let str4 = "BlockCHAIN"
let str5 = "Meta"
// get the capitalized representation
print(str1.localizedUppercase)
print(str2.localizedUppercase)
print(str3.localizedUppercase)
print(str4.localizedUppercase)
print(str5.localizedUppercase)

Explanation

  • Line 2: We import the Foundation framework, which provides methods and functionalities such as the localizedUppercase property.
  • Lines 5 to 9: We create some strings.
  • Lines 12 to 16: We get the uppercase representations of the strings we created using the localizedUppercase property and print the returned values to the console.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources