Simple question about iterating 2 arrays in objective-c -


i'm iterating nsarray in objective-c with:

for (id object in array1) {   ... } 

i have array2, , need access same index of current array1.

should use statement ?

thanks

you have several options:

  1. use c-style loop dan suggested

  2. keep track of current index in separate variable in fast-enumeration approach:

    int index = 0; (id object in array1) {    id object2 = [array2 objectatindex:index];    ...    ++index; } 
  3. use enumerateobjectsusingblock: method (os 4.0+):

    [array1 enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop){     id obj2 = [array2 objectatindex:idx];     ... }]; 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -