Effective Objective-C 2.0 编写高质量iOS与OS X代码 对象等同性
- (BOOL)isEqual:(id)object { if(self == object) return YES; if([self class] != [object class] ) return NO; ConcreteId *otherId = (ConcreteId*)object; if(![someProperty isEqual:otherId.someProperty]) return NO; // ……… 比较其他属性值 return YES; }
- (BOOL)isEqual:(id)object { if([self class] ==[ object class ]) { return [self isEqualToPerson:(EOCPerson*)object}; }else { return [self isEqual:object]; } }
NSMutableSet *set = [NSMutableSet new]; NSMutableArray *arrayA = [@[@1, @2] mutableCopy]; [set addObject:arrayA]; NSLog(@“set = %@“,set); // set = {((1,2))}
NSMutableArray *arrayB = [@[@1, @2] mutableCopy]; [set addObject:arrayB]; NSLog(@“set = %@“,set); // set = {((1,2))}
NSMutableArray *arrayC = [@[@1] mutableCopy]; [set addObject:arrayC]; NSLog(@“set = %@“,set); // set = {((1),(1,2))}
[arrayC addObject:@2]; NSLog(@“set = %@“,set); // set = {((1,2),(1,2))}
NSSet *setB = [set copy]; NSLog(@“setB = %@“,setB); // setB = {((1,2))}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。