views:

99

answers:

2

I want to use the object's reference value as a key into a dictionary, as opposed to a copy of value of the object. So, I essentially want to store an object associated with a particular instance of another object in a dictionary and retrieve that value later.

Is this possible? Is it completely against the idea of NSDictionary? I can tell that I am probably approaching this the wrong way because the dictionary wants me to implement NSCopying on the object itself, which doesn't really make sense in terms of what I'm doing. I can see that what I should really be doing is wrapping the pointer value, but that seems a little mad.

Advice would be appreciated.

A: 

NSMutableDictionary has been designed to only deals with Objective-C instances. For example, when you call setObject:forKey: method calls retain on the key and copyWithZone: on the value.

If you want to have a dictionary structure and to be able to deal with arbitrary key and value, then you can go with CFMutableDictionary. You can describe precisely what is done with key and values; it is flexible enough to deal with arbitrary pointer or event char * strings.

Laurent Etiemble
+1  A: 

I think you can use [NSValue valueWithPointer:object]

mustISignUp
That worked rather well, thanks!
Ranking Stackingblocks