Using the given code below I try to iterate over the dictionary wordList
which fails with the issue Instance method 'identified(by:)' requires that '(key: Int, value: [String : String])' conform to 'Hashable'
.
So my guess is that I have either to apply the protocol Hashable
somehow to the Int
of the dictionary or there may be another solution which concerns the usage of .identified(by:)
Thank you very much for the help!
struct ContentView: View {
@State var wordOrder = ["DE", "EN"]
let wordList: [Int: [String: String]] = [
0: [
"DE": "Hallo Welt",
"EN": "hello world"
],
1: [
"DE": "Tschüss",
"EN": "goodbye"
],
2: [
"DE": "vielleicht",
"EN": "maybe"
]
]
var body: some View {
Group {
NavigationView {
List() {
ForEach(wordList.identified(by: \.self)) { wordListEntry in
let lang1 = wordListEntry[wordOrder[0]]
let lang2 = wordListEntry[wordOrder[1]]
WordRow(lang1, lang2)
}
}
.navigationBarTitle(Text("Alle Wörter"))
}
}
}
}