I want to get the index of the current object when using fast enumeration, i.e.
for (MyClass *entry in savedArray) {
// What is the index of |entry| in |savedArray|?
}
I want to get the index of the current object when using fast enumeration, i.e.
for (MyClass *entry in savedArray) {
// What is the index of |entry| in |savedArray|?
}
Look at the API for NSArray and you will see the method
So give that one a try
If you want to access the index or return outside block here is a piece of code that can be useful. (considering the array is an array of NSString).
This question has already been answered, but I thought I would add that counting iterations is actually the technique mentioned in the iOS Developer Library documentation:
I was sure there would be a fancy trick, but I guess not. :)
I suppose the most blunt solution to this would be to simply increment an index manually.
Alternatively, you could just not use fast enumeration.
A simple observation: If you initialize the index to -1 and then put the ++index as the first line in the for loop, doesn't that cover all bases (provided someone doesn't slip code in front of the increment)?