iphone - Find text in NSArray -


i have several custom objects in nsarray, need search through objects , fnd index of object has property matches string. should using each loop? need relatively fast search each time new character entered in textfield.

nspredicate neat, overkill (and won't give index of found object; object itself).

the paired array approach, work, feels odd me (probably because it's using paired array).

i either use for() loop (and break; when found looking for), or use block enumerator:

__block nsinteger indexofmatchingobject = nsnotfound; [myarray enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop) {   if ([[obj property] doeswhatimlookingfor]) {     indexofmatchingobject = idx;     *stop = yes;   } }]; 

or different variant:

nsinteger indexofmatchingobject = [myarray indexofobjectpassingtest:^(id obj, nsuinteger idx, bool *stop) {   return ([[obj property] doeswhatimlookingfor]); }]; 


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..." -