I was wondering how keys work in a NSDictionary. Usually, I will use a NSString as a key for example:
NSString *stringKey = @"stringKey";
[mydict objectForKey:stringKey];
What if I wanted to use a NSNumber:
NSNumber *numberKey = [NSNumber numberWithInt:3];
[mydict objectForKey:numberKey];
Does the dictionary go look for the key with number 3? or would it just compare the address of the numberKey?
Two keys are equal if and only if
[key1 isEqual:key2]. Some classes may go with the-[NSObject isEqual:]implementation ofreturn self == other;, but it’s quite common for classes (such asNSString,NSNumber, etc) to override it to do more context-specific comparison.