Posted By

suibhne on 11/02/09


Tagged

Objective-c iphone


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

davidsi
avanadra
cnathan


NSMutableDictionary Loop


 / Published in: Objective C
 

Just a simple loop around a mutable dictionary object which I always seem to forget.

  1. NSMutableDictionary* aDictionary = (initialized with some objects)
  2.  
  3. for (id theKey in aDictionary) {
  4. id anObject = [[aDictionary objectForKey:theKey] retain];
  5. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mracoker on March 21, 2010

just what i need!

Posted By: dc_2000 on January 7, 2011

You realize that anObject in the code above has to be released? So technically an example above has a memory leak...

If anObject is used within the scope of 'for', it's better not to use 'retain'

Posted By: suibhne on January 24, 2011

Thanks dc_2000. Its assuming that you do something with anObject and then release it after the fact but I suppose that wasn't clear :)

You need to login to post a comment.