KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
All objects used as keys in NS(Mutable)Dictionaries must support the NSCopying protocol, and those objects are copied when they're used in the dictionary. I frequently want to use heavier weight objects as keys, simply to map one object to another. What I really mean when I do that is effectively: [dictionary setObject:someObject forKey:[NSValue valueWithPointer:keyObject]]; ("When I come back and hand you this same key object instance again, get me that same value out.") ...which is exactly what I end up doing to get around this design sometimes. (Yes, I know about NSMapTable in desktop Cocoa; but e.g. iPhone doesn't support this.) But what I don't really get is why copying the key is necessary or desirable in the first place. What does it buy the implementation or caller?
Tags (comma-separated)
Save Edits
Cancel