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!")
Despite this simplicity of syntax, Swift’s String type is a fast, modern string implementation. Every string is composed of encoding-independent Unicode characters, and provides support for accessing those characters in various Unicode representations. Swift’s String type is bridged with Foundation’s NSString class.
Substrings in Swift have most of the same methods as strings, which means you can work with substrings the same way you work with strings. However, unlike strings, you use substrings for only a short amount of time while performing actions on a string. When you’re ready to store the result for a longer time,...
The syntax for string creation and manipulation is lightweight and readable, with a string literal syntax that’s similar to C. String concatenation is as simple as combining two strings with the + operator, and string mutability is managed by choosing between a constant or a variable, just like any other value in Swift.
String and character comparisons in Swift aren’t locale-sensitive. To check whether a string has a particular string prefix or suffix, call the string’s hasPrefix (_:) and hasSuffix (_:) methods, both of which take a single argument of type String and return a Boolean value.
For those who want to use LocalizedStringKey. Since iOS 14 you can use .textCase(.uppercase)
on Text.
Text(LocalizedStringKey("keyName"))
.textCase(.uppercase)
You can do this simply in this way
Text("Hello World!".uppercased())
For LocalizedStringKey
you can use this.
Text(LocalizedStringKey("keyName")).textCase(.uppercase)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With