Re: iterating and removing objects from a collection

2009-12-01 Thread Jeremy Pereira
On 30 Nov 2009, at 21:21, Ken Thomases wrote: > On Nov 30, 2009, at 2:45 PM, Dennis Munsie wrote: > >> I run into this all the time where I need to iterate through an >> NSMutableArray (or set, etc, etc) and remove some of the items. My normal >> pattern has been this: >> >> NSMutableSet *remo

Re: iterating and removing objects from a collection

2009-11-30 Thread Jens Alfke
On Nov 30, 2009, at 1:37 PM, Sherm Pendley wrote: > A safe way to do that is to iterate backwards, starting at the max > index and counting down to 0. That way, removing the item at the > current index will only change the indexes of the items you've already +1. I often use this idiom. You can d

Re: iterating and removing objects from a collection

2009-11-30 Thread Sherm Pendley
On Mon, Nov 30, 2009 at 4:21 PM, Ken Thomases wrote: > On Nov 30, 2009, at 2:45 PM, Dennis Munsie wrote: > > Some alternatives: > > * Iterate over the array just using an index, rather than fast enumeration > (or NSEnumerator). A safe way to do that is to iterate backwards, starting at the max i

Re: iterating and removing objects from a collection

2009-11-30 Thread Ken Thomases
On Nov 30, 2009, at 2:45 PM, Dennis Munsie wrote: > I run into this all the time where I need to iterate through an > NSMutableArray (or set, etc, etc) and remove some of the items. My normal > pattern has been this: > > NSMutableSet *removeSet = [[NSMutableSet alloc] init]; > for(NSObject *foo