Search code examples
swiftuixcode11

SwiftUI: Uppercase a localized string for a view, e.g. `Text`?


Using Xcode beta 6 and SwiftUI, creating a Text view using a >localized< string, how can I uppercase it without having to make the localized string value uppercased? I guess I want a ViewModifier for changing case, but it does not seem to exist?

Text("SignIn.Body.Instruction".uppercased()) will uppercase the localization key, so that will not work, as instructed in this SO question about uppercasing a non-localized string.


Solution

  • It is now possible with all new textCase ViewModifier (Xcode 12 Beta 3), like so:

    Text("SignIn.Body.Instruction")
        .textCase(.uppercase)
    

    Or lowercase:

    Text("SignIn.Body.Instruction")
        .textCase(.lowercase)