Re: iterating and removing objects from a collection
Re: iterating and removing objects from a collection
- Subject: Re: iterating and removing objects from a collection
- From: Jens Alfke <email@hidden>
- Date: Mon, 30 Nov 2009 15:25:54 -0800
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 do it going forwards, but it introduces an if/else that makes the code sort of confusing (and easy to mess up.)
It's also more efficient than removing the elements in forwards order (proof of this is left as an exercise for the reader.)
—Jens_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden