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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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:
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.