I was wondering why the Text
View in SwiftUI is (as far as I know) the only View that accepts a LocalizedStringRessource in its init. Are there better alternatives? I know there is LocalizedStringKey, which works great with SwiftUI Views but is limited if you want to access the localised string in non-UI code. This results in the inconvenient situation of writing code like this:
struct LocalizedView: View {
let localizedString = LocalizedStringResource("Localize Me!")
var body: some View {
Text(localizedString)
// Does not work
// Label(localizedString, systemImage: "questionmark")
// Inconvenient
Label(String(localized: localizedString), systemImage: "questionmark")
}
}
Best, Chris