• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Remove Items From NSSet (safely)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remove Items From NSSet (safely)


  • Subject: Re: Remove Items From NSSet (safely)
  • From: Quincey Morris <email@hidden>
  • Date: Sun, 11 Jan 2009 23:37:41 -0800

On Jan 11, 2009, at 23:17, 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.

Constructing a new set of the objects to be removed sounds clunky until you do it, and then you find it's just a couple of lines of inoffensive code.


It also has one advantage (in general) over removing the objects as you iterate (if you could do it the easy way). Assuming you use minusSet to remove the objects at the end of iterating, it generates a single KVO notification for the whole operation instead of a KVO notification for each removal. Sometimes that's a big win, other times it doesn't matter much one way or another.


_______________________________________________

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


References: 
 >Remove Items From NSSet (safely) (From: "Bridger Maxwell" <email@hidden>)

  • Prev by Date: Re: Remove Items From NSSet (safely)
  • Next by Date: Re: UTExportedTypeDeclarations vs CFBundleDocumentTypes
  • Previous by thread: Re: Remove Items From NSSet (safely)
  • Next by thread: iTunes-like tail truncation for attributed strings
  • Index(es):
    • Date
    • Thread