nsarray - iPhone - Iterating through Array of dictionaries and getting an object -
in application, i'm having nsarray holds objects of nsdictionary. in each dictionary, there's 1 "primary" holds value of type nsnumber stores "yes" or "no" (boolean value). , dictionary object in array can have value "yes". without using loops how can dictionary object "primary" key yes?
you can call convenience method on nsarray
find object, aware, such method still uses loop internally find object.
nsuinteger indexofprimary = [array indexofobjectpassingtest:^(id obj, nsuinteger idx, bool *stop) { return [[obj objectforkey:@"primary"] boolvalue]; }]; nsdictionary *primary = nil; if (indexofprimary != nsnotfound) { primary = [array objectatindex:indexofprimary]; }
another option -[nsarray filteredarrayusingpredicate:]
.
Comments
Post a Comment