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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -