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:
use c-style loop dan suggested
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; }
use
enumerateobjectsusingblock:
method (os 4.0+):[array1 enumerateobjectsusingblock:^(id obj, nsuinteger idx, bool *stop){ id obj2 = [array2 objectatindex:idx]; ... }];
Comments
Post a Comment