On Jan 11, 2009, at 11:17 PM, Bridger Maxwell wrote:

I have an NSSet which I need to iterate through and remove any objects if they fail a certain test (this is a client/server setup, so I am testing the connection to connected clients). However, if I remove an object from the set while iterating through it, I get this message logged to the console.

**** Collection <NSCFSet: 0x10567e0> was mutated while being enumerated.*

Is there a better way to remove objects from a set? Perhaps there is a safe
iteration that allows objects to be removed? I supposed I could keep a
separate list of objects that need to be removed, and then remove them
afterwards, but that seems like a clunky solution.


How about something like this?

for (id obj in [theSet allObjects])
{
        if (something)
        {
                [theSet removeObject: obj
        }
}

j o a r


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to