Best way to remove from NSMutableArray while iterating?
Posted
by Andrew Grant
on Stack Overflow
See other posts from Stack Overflow
or by Andrew Grant
Published on 2008-09-21T19:43:20Z
Indexed on
2010/06/17
21:33 UTC
Read the original article
Hit count: 230
objective-c
|cocoa
In Cocoa, if I want to loop through an NSMutableArray and remove multiple objects that fit a certain criteria, what's the best way to do this without restarting the loop each time I remove an object?
Thanks,
Edit: Just to clarify - I was looking for the best way, e.g. something more elegant than manually updating the index I'm at. For example in C++ I can do;
iterator it = someList.begin();
while (it != someList.end())
{
if (shouldRemove(it))
it = someList.erase(it);
}
© Stack Overflow or respective owner