Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear a dictionary?

I'm currently doing the following to clear out an NSMutableDictionary

[myDictionary release];
myDictionary = [[NSMutableDictionary alloc] init];

The release line doesn't actually release any objects in the dictionary. I can still see all of them on the next line. It isn't until the alloc line is executed that the dictionary is zeroed out. Is there a better way to do it?

like image 654
4thSpace Avatar asked Dec 31 '09 21:12

4thSpace


People also ask

What method is used to empty a dictionary?

The clear() method removes all the elements from a dictionary.

Can I use Clear () method to delete the dictionary?

Python dictionary clear() method is used to remove all elements from the dictionary. When you have a dictionary with too many elements, deleting all elements of the dictionary one after another is a very time taken process, so use clear() method to delete all elements at once rather than deleting elements one by one.


1 Answers

I can't test it at the moment, but have you tried the removeAllObjects method of NSMutableDictionary?

http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html#//apple_ref/occ/instm/NSMutableDictionary/removeAllObjects

like image 187
Andy White Avatar answered Sep 18 '22 21:09

Andy White