I'd like to create an NSMutableDictionary that's keyed on a particular object and maps to an NSNumber. The object comes from a 3rd-party library and doesn't implement the copyWithZone method. The compiler understandably complains about the unrecognized selector (copyWithZone) being sent to the object, using the code:
[dictionary setObject:[NSNumber numberWithInt:index] forKey:someObject];
Since I didn't want to create my own copyWithZone method for a 3rd-party library object which I shouldn't need to know how to copy, I stayed away from creating a category that implements the method.
My hack was to store the memory address in an NSNumber by converting it to a long long:
[dictionary setObject:[NSNumber numberWithInt:index] forKey:[NSNumber numberWithLongLong:(long long)someObject]];
To retrieve the value:
NSNumber *indexNumber = [dictionary objectForKey:[NSNumber numberWithLongLong:(long long)someObject]];
This seems very hackish to me. What would be a cleaner way to handle the object-to-int mapping?