Objective-C For-In Loop Get Index
Arrays are guaranteed to iterate in object order. So:
NSUInteger index = 0;for(NSString *string in anArray){ NSLog(@"%@ is at index %d", string, index); index++;}
Alternatively, use the block enumerator:
[anArray enumerateObjectsUsingBlock: ^(NSString *string, NSUInteger index, BOOL *stop) { NSLog(@"%@ is at index %d", string, index); }];
Try this.
for (NSString *string in anArray){ NSUInteger index = [anArray indexOfObject:string];}