How to get index of an item in an array
use NSArray's indexOfObject:
method. Such as the following:
NSUInteger fooIndex = [someArray indexOfObject: someObject];
int totalElements = [anArray count];for(int i=0; i < totalElements; i++){ data = [myArray indexOfObject:i];}
The above code will give you the data if you pass in the index
NSString *haystackText = @"Hello World";int totalElements = [anArray count];for(int i=0; i < totalElements; i++){ BOOL result = [haystackText caseInsensitiveCompare:[myArray objectAtIndex:i] == NSOrderedSame; if(result) { NSUInteger fooIndex = [myArray indexOfObject: haystackText]; return fooIndex; }}
The code above will first find the element in the array and if it exists then return the index.