Safe way of iterating over an array or dictionary and deleting entries?
Posted
by mystify
on Stack Overflow
See other posts from Stack Overflow
or by mystify
Published on 2010-05-07T10:06:32Z
Indexed on
2010/05/07
10:08 UTC
Read the original article
Hit count: 145
I've heard that it is a bad idea to do something like this. But I am sure there is some rule of thumb which can help to get that right.
When I iterate over an NSMutableDictionary or NSMutableArray often I need to get rid of entries. Typical case: You iterate over it, and compare the entry against something. Sometimes the result is "don't need anymore" and you have to remove it. But doing so affects the index of all the rows, doesn't it?
So how could I safely iterate over it without accidently exceeding bounds or jumping over an element that hasn't been checked?
© Stack Overflow or respective owner