I’m trying to access my dictionary object. Here’s my code:
int tag = object.tag;
CGPoint point = [[self.dict objectForKey:tag] CGPointValue];
The problem is objectForKey is supposed to take an Objective-C object, not an int. I tried wrapping tag into an NSNumber with [NSNumber numberWithInt:tag] and passing that into objectForKey: but it returns a null object.
Any ideas? Thanks
If you are using numbers as strings for dictionary keys, you should turn the
intinto aNSStringorNSNumberto use it as a dictionary key. Here’s how to do it for a string:As @Hughes BR mentions in a comment, the requirement for the key object is that it must conform to the
NSCopyingprotocol.