Possible Duplicate:
Best way to remove from NSMutableArray while iterating?
Mods: I realized this was a duplicate of this question, can you close/delete it?
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 don’t want to create a temporary or new array, you can use this:
(But a temporary
NSIndexSetis used.)Remark: My thought was that it might be more efficient to remove all matching elements “at once” instead of removing each element separately during the iteration, as suggested by Richard J. Ross III.
But a short test showed that this is not the case. Removing every second element from an array with 1000000 elements takes almost the same time with both methods on my computer.