Необходимо сравнивать значения NSNumbers, а не объектов.
Вы можете использовать objectsPassingTest:
Пример:
NSMutableSet *set = [[NSMutableSet alloc] init];
NSNumber *num1 = [NSNumber numberWithInt:5];
NSNumber *num2 = [NSNumber numberWithInt:5];
NSNumber *num3 = [NSNumber numberWithInt:3];
[set addObject:num1];
NSSet *filteredSet;
filteredSet = [set objectsPassingTest:^(id obj,BOOL *stop){
return [obj isEqualToNumber:num2];
}];
NSLog(@"Contains num2: %@", (filteredSet.count == 1) ? @"YES" : @"NO");
filteredSet = [set objectsPassingTest:^(id obj,BOOL *stop){
return [obj isEqualToNumber:num3];
}];
NSLog(@"Contains num3: %@", (filteredSet.count == 1) ? @"YES" : @"NO");
Вывод NSLog:
Contains num2: YES
Contains num3: NO
Или, если желательно использовать предикаты:
filteredSet = [set filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"SELF == %@", num2]];
NSLog(@"Contains num2: %@", (filteredSet.count == 1) ? @"YES" : @"NO");
filteredSet = [set filteredSetUsingPredicate:[NSPredicate predicateWithFormat:@"SELF == %@", num3]];
NSLog(@"Contains num3: %@", (filteredSet.count == 1) ? @"YES" : @"NO");