一定有什么东西在你的代码别的,你是不是做对了,因为覆盖方法为您展示在OP导致NSMutableSet
认识到我的对象是相同的:
Test.h:
#import "Foundation/Foundation.h"
@interface Test : NSObject
@end
Test.m:
#import "Test.h"
@implementation Test
- (BOOL)isEqual:(id)anObject {
return YES;
}
- (NSUInteger)hash {
return 1;
}
@end
的main.c:
#include <CoreFoundation/CoreFoundation.h>
#import "Test.h"
int main (int argc, const char * argv[]) {
Test *t1 = [[Test alloc] init];
Test *t2 = [[Test alloc] init];
Test *t3 = [[Test alloc] init];
Test *t4 = [[Test alloc] init];
NSSet *s = [NSMutableSet setWithObjects:t1, t2, t3, t4, nil];
NSLog(@"%lu", s.count);
return 0;
}
这个片段产生1
,符合市场预期。
添加相同的对象不会导致错误,它只是不会改变设置。 – vikingosegundo 2011-12-24 04:02:13