filtering - Filter is not working in ios -
i used nspredicate filter nsmutablearray 1 & multiple values,first tried filter price, have saved nsdictionary value nsmutablearray (i.e) resultarray,here code me,
(int i=0; i<=resultarray.count; i++) { nsdictionary *dict=resultarray[i]; nslog(@"dict %@",dict); nspredicate *predit=[nspredicate predicatewithformat:@"(price == %@)", @"100"]; nsarray *resultar = [[dict allvalues] filteredarrayusingpredicate:predit]; nslog(@"output %@",resultar); } dict { name = "black eyed peas"; percentage = 0; price = 80; }
and result array is:
result ( { name = "black eyed peas"; percentage = 0; price = 80; }, { name = "black gram"; percentage = 0; price = 56; }, { name = "channa white"; percentage = 0; price = 100; }, { name = "double beans"; percentage = 0; price = 95; }, { name = "gram dall"; percentage = 0; price = 100; }, { name = "green moong dal"; percentage = 0; price = 150; }, { name = "ground nut"; percentage = 0; price = 140; }, { name = "moong dal"; percentage = 0; price = 75; }, { name = "orid dal"; percentage = 0; price = 100; }, { name = "toor dal"; percentage = 0; price = 150; } )
expected output is
( { name = "channa white"; percentage = 0; price = 100; }, { name = "gram dall"; percentage = 0; price = 100; }, { name = "orid dal"; percentage = 0; price = 100; } )
but giving error
reason: '[<__nscfnumber 0x146db5e0> valueforundefinedkey:]: class not key value coding-compliant key price.
above code correct filtering else give me idea filter resultarray expected output
follow below code.i use predicate here.
nspredicate *predit=[nspredicate predicatewithformat:@"price %@",100]; nsarray *resultar = [resultarray filteredarrayusingpredicate:predit];
in above code
if give like gives same price data.
you have delete or remove [dict allvalues] code.
instead of [dict allvalues] need add resultarray.because array.
Comments
Post a Comment