Is there any “easy” way to have clean objective-c containers, such as NSMutableDictionary or CFMutableDictionary, that don't increase the number of references to added objects without using the standard C ++ library?
EDIT: The explanation is the reason I want this, so I can implement a kind of Exactly One template - the class will have a static method named getThing: (NSString *). If this method detects a Thing associated with a name in some static data structure (a dictionary of links without links), it returns it, otherwise it creates one, adds it to the structure under this name, and returns it. This Thing object can be saved by the client as desired, but when its reference count drops to 0 (and dealloc is called), it should be removed from the dictionary. Thus, I cannot release it when adding and saving it when deleting - dealloc will be called again, and I do not want this. That's why I need a non-incremental dictionary. If there is another way to get what I want, let me know, although I'm surethat the verified answer gives me what I want. Thank!
source
share