I have an NSMutableOrderedSet from which I add and remove MTLModels. The hash and isEqual methods will return true for two objects, but containsObject will return false.
Sometimes this code works, and sometimes not.
models count: 1
isEqual: 1
hashes equal: 1
containsObject: 0
How is this possible, the code below can print above?
@property (nonatomic, strong) NSMutableOrderedSet *models;
- (void)remove:(MTLModel *)model {
NSLog(@"models count: %d", self.models.count);
MTLModel *modelInSet = (MTLModel *)self.models.firstObject;
NSLog(@"isEqual: %d", [modelInSet isEqual:model]);
NSLog(@"hashes equal: %d", modelInSet.hash == model.hash);
NSLog(@"containsObject: %d", [self.models containsObject:model]);
}
Update:
YES is returned as a continuation when NSMutableOrderedSet returns NO:
[[self.models array] containsObject:model]
Update 2:
If I check to see if modelInSet is contained in self.models, this also returns NO, even if it is the object returned by firstObject.
source
share