I want to display a dictionary in SwiftUI Table
like shown below. But unlike List
, Table
doesn’t have a id parameter, so the compiler reports an error:
Type 'Dictionary<String, String>.Element' (aka '(key: String, value: String)') cannot conform to 'Identifiable'
@State var dic: [String : String] = [
"name" : "Tim",
"company" : "Apple"
]
Table(dic.map{$0}.sorted{ $0.key < $1.key }) {
TableColumn("Name") { item in
Text(item.key)
}
}
So the problem is how to makes the tuple here confirm to Identifiable
?