I have a situation like i have array of dictionaries, in which each key has array of specific object. like this.
// example setup
struct FruitsData {
var name: String?
var id: String?
}
tableViewSource = [String : [FruitsData]]
so i have to apply filter on this inner array. but i am unable to update the value in final array. I have written this code.
tableViewSource = tableViewSource.filter { ( dictData: (key: String, value: [FruitsData])) -> Bool in
var arrFruitsData = dictData.value
arrFruitsData = arrFruitsData.filter{ ( $0.id != nil) }
if arrFruitsData.count == 0 {
self.tableViewHeaders = self.tableViewHeaders.filter { $0 != dictData.key }
}
return true
}
like i have remove those values in array whose id has been removed.
for eg if i have these values in array.
var array = ["A": [FruitsData(name: "apple", id: "5"), FruitsData(name: "apricot",id: "")], "M": [FruitsData(name: "mango", id: "9"), FruitsData(name: "grapes", id: "")]]