Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: LocalizedStringKey with indices

Tags:

swift

swiftui

i have a Localizable.strings with following content:

"Question1"       = "blablabla";
"Question2"       = "blablablub";
"Question3"       = "bliblablub";

now I want to print my questions in a ForEach. But my following syntax doesn't work. How can I solve my problem?

  List(){
            ForEach (1..<4) { value in   
                Text(LocalizedStringKey("Question\(value)") )}
            }
like image 278
Michael Avatar asked Dec 04 '25 17:12

Michael


1 Answers

Here is a solution. Tested with Xcode 12.1 / iOS 14.1

ForEach (1..<4) { value in
    Text(LocalizedStringKey(stringLiteral: "Question\(value)"))
}
like image 162
Asperi Avatar answered Dec 06 '25 09:12

Asperi