Please have a look at this code:
Card *first = [[Card alloc] initWithFace:@"Ace" andSuit:@"Hearts"];
Card *second = [[Card alloc] initWithFace:@"Ace" andSuit:@"Hearts"];
if ([first isEqual:second])
NSLog(@"Equal");
else
NSLog(@"Not equal"); //WHY???
NSLog tells me these two objects are not equal. But why? And what should I do to make them equal?
You have to implement your own
isEqual:method within the Card class.This would compare the face and suit of the passed in card object to self, and return an appropriate BOOL value. See here for more details on the base (NSObject) implementation and how you should amend it.
An untested, typed-in-the-browser implementation would be something like:
You must also implement
hashsuch that two equal objects return the same hash value.