I tried to group the data get from API and display it in a expanding list like How to create expanding lists – SwiftUI Here is some sample data .
[
{
"name": "Hair Cut",
"createDate": 1600423060,
"voucherID": 12311,
"type": "service",
"expiryDate": 1600682257,
"trxnID": 2683125
},
{
"name": "Hair Cut",
"createDate": 1600423060,
"voucherID": 31231,
"type": "service",
"expiryDate": 1600682257,
"trxnID": 2683124
},
{
"name": "Package B",
"createDate": 1596217117,
"voucherID": 12312,
"type": "service",
"expiryDate": 0,
"trxnID": 2423309
}
]
Now I already group the data by using the dictionary Dictionary(grouping: self.vouchers, by: {$0.name!})
into @Published var gVouchers = Dictionary<String, Any>()
. So the problem now is how I display them in a expanding list. The expanding list use a children which I don't have in dictionary. So is there any method to do so? Or I cannot use the dictionary to do the grouping?