Take the 2-minute tour ×  What is the best way to know when I
have reached the last object in an array when using fast
enumeration? Is there a better way than incrementing an int and
then comparing that to the length of the array?  share|improve
this question add comment  3 Answers  up vote 6 down vote
accepted  If you are starting with an array get out the last
element (there's a specific call for that) and compare each
element you get in the enumerator against that. Something like:
id lastEl = [myArray lastObject];  for ( id anEl in myArray )
if ( anEl == lastEl )      .....  // do the last thing  The
comparison cost is the same as with the counter, but then you
don't have the cost of incrementing the counter or mistakes that
invariably arise when you forget to increment the counter.
share|improve this answer I'd agree with this, but I believe it
is "lastObject" not "lastElement". –  slycrel Dec 27 '10 at
22:33 Well now you and I agree! That's what I get for not
checking the SDK docs for the call. –  K