I've finally pinpointed the exact issue to a problem I've been having, but I'm not sure how to fix it. Here is the general gist of what is happening: I have an array called wordArray, and I am iterating through it. This array can contain strings that are identical to each other and different from one another. All I want to do is retrieve the index of the particular instance that I am currently iterating, so I the simplified version is this:
for(NSString* stringInWordArray in wordArray){
NSLog(@"String is: %@ Index is: %d",stringInWordArray,[wordArray indexOfObject:stringInWordArray]);
}
This will obviously print out the String, and the index of the string, however, according to the apple documentation, the indexOfObject method "Returns the lowest index whose corresponding array value is equal to a given object." This is a problem for me because if I have an array that looks like this:
["fruit","fruit","panda","happy",nil];
Then this will print:
String is fruit Index is 0
String is fruit Index is 0
String is panda Index is 2
String is happy Index is 3
Where I want the indices to print 0,1,2,3. Any workarounds for this issue?