Michael
Michael

Reputation: 726

SwiftUI: LocalizedStringKey with indices

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)") )}
            }

Upvotes: 3

Views: 345

Answers (1)

Asperi
Asperi

Reputation: 257703

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

ForEach (1..<4) { value in
    Text(LocalizedStringKey(stringLiteral: "Question\(value)"))
}

Upvotes: 4

Related Questions