The documentation for [NSArray containsObject:]
says:
This method determines whether anObject is present in the receiver by sending an isEqual: message to each of the receiver’s objects (and passing anObject as the parameter to each isEqual: message).
The problem is that you are comparing references to objects rather than the values of the objects. To make this specific example work, you will either need to send [collection containsObject:]
an instance of a variable it contains (e.g. A
, B
, or C
), or you will need to override the [NSObject isEqual:]
method in your Fruit class.