Re: Fast Enumeration and remove elements

2015-01-18 Thread Quincey Morris
On Jan 18, 2015, at 12:45 , Trygve Inda wrote: > > NSMutableDictionary* collection; // keys are myID, values are MyObject > > for (MyObject* object in [[self collection] allValues]) > { >[collection removeObjectForKey:[object myID]]; > } What Ken said, plus … — If the collection of values

Re: Fast Enumeration and remove elements

2015-01-18 Thread Ken Thomases
On Jan 18, 2015, at 2:45 PM, Trygve Inda wrote: > So is this safe... > > NSMutableDictionary* collection; // keys are myID, values are MyObject > > for (MyObject* object in [[self collection] allValues]) > { >[collection removeObjectForKey:[object myID]]; > } > > It would seem that this i

Fast Enumeration and remove elements

2015-01-18 Thread Trygve Inda
Apple says: > It is not safe to remove, replace, or add to a mutable collection’s elements > while enumerating through it. If you need to modify a collection during > enumeration, you can either make a copy of the collection and enumerate using > the copy or collect the information you require dur