• 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
remove elements during the iteration on NSMutableDictionary
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

remove elements during the iteration on NSMutableDictionary


  • Subject: remove elements during the iteration on NSMutableDictionary
  • From: "Wayne Shao" <email@hidden>
  • Date: Wed, 6 Aug 2008 07:27:36 -0700

Hi

Please see the question in the comments of the following code.

NSMutableDictionary* aDictionary = (initialized with some objects)

for (id theKey in aDictionary) {
  id anObject = [[aDictionary objectForKey:theKey] retain];

 [aDictionary removeObjectForKey:theKey];
 // Question: will this removal break or corrupt the loop of enumerating the
elements?

 [anObject someMessage];
}

in java, Iterators allow the caller to remove elements from the underlying
collection during the iteration. is there similar semantics in objective-c?

--
Wayne Shao
_______________________________________________

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

  • Follow-Ups:
    • Re: remove elements during the iteration on NSMutableDictionary
      • From: Negm-Awad Amin <email@hidden>
  • Prev by Date: Dumb Q
  • Next by Date: Re: Dumb Q
  • Previous by thread: Re: Dumb Q
  • Next by thread: Re: remove elements during the iteration on NSMutableDictionary
  • Index(es):
    • Date
    • Thread