ios - Filtering Arrays Containing Multiple Data Types in Swift3 -
i have array like:-
var arraydata : array<dictionary<string, [bottlemodel]>> = []
bottle model :-
class bottlemodel: nsobject { var name : string var price : int var reviews : int var category : string var quantity : string var id : string var shopdata : shopmodel }
i want filtered array price > 2000
i tried let searchbyints = arraydata.filter({m in m.price < 200})
getting below error:
contextual closure type '(dictionary) -> bool' expects 1 argument, 0 used in closure body
how filter such kind of array based on price
working code:
let searchbyints = arraydata.filter { $0.values.contains { $0.contains { $0.price > 2000 } } }
by way please write following using literals:
var arraydata : [[string : [bottlemodel]]] = []
still no idea if want because goal very unclear. have array of dictionaries of arrays contain values want filter out. if bottlemodel
costs more 2000 want keep entire array contained in , dictionary array in? might want map entire data 1 flat array before or after filtering.
alternative using flatmap
:
let flat = arraydata.flatmap { $0.values.flatmap { $0 } } let searchbyints2 = flat.filter { $0.price < 200 } // or other criteria
Comments
Post a Comment