'How to create an uppercase version of a String in SwiftUI?

It is possible using Swift to create an uppercase version of a String with

let str = "Hello World!"
print(str.uppercased())

This code will print "HELLO WORLD!" into the Xcode console. But how do you create an uppercase of a String like the following using SwiftUI?

Text("Hello World!")


Solution 1:[1]

You can do this simply in this way

Text("Hello World!".uppercased())

For LocalizedStringKey you can use this.

Text(LocalizedStringKey("keyName")).textCase(.uppercase)

Solution 2:[2]

For those who want to use LocalizedStringKey. Since iOS 14 you can use .textCase(.uppercase) on Text.

Text(LocalizedStringKey("keyName"))
  .textCase(.uppercase)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Maksymilian Tomczyk