The documentation for NSDictionary says that the method objectForKey returns nil if the NSDictionary does not contain your key; however, isn’t nil the same as zero? If so, how do I know if the return value means that the dictionary contains the key mapped to zero or if that key is just non-existant?
The documentation for NSDictionary says that the method objectForKey returns nil if the NSDictionary
Share
NSDictionaries (and, indeed, all Cocoa collection objects) can only contain Objective-C objects, not C primitives like
int. Therefore, were you to store0in a dictionary, you’d do it like this:and therefore, retrieving it would go like this:
This concept of ‘wrapping’ a C primitive in an object to store it in a collection, then ‘unwrapping’ it on the other end is very common in Cocoa. (You might also look into
NSValueif you’re trying to work with non-number values.)