I understand the difference between isKindOfClass: and isMemberOfClass: but I came across something I do not understand:
-(UIImage *)doSomething:(id)item
{
UIImage *image;
if ([item isKindOfClass:[NSDictionary class]]) {
NSDictionary *dictionary = item;
NSData *data = [dictionary objectForKey:@"image"];
image = [[UIImage alloc] initWithData:data];
} else { // if item is UIImage
image = item;
}
return image;
}
If I am using isKindOfClass in this context everything works as expected. If I use isMemberOfClass I get the following crash asking for the size of the image later:
-[__NSDictionaryI size]: unrecognized selector sent to instance 0x123456
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI size]: unrecognized selector sent to instance 0x123456'
I read other posts like this one but I couldn't find anything that would come closer.