我想覆盖这个方法来比较两个对象。
-(BOOL)isEqual:(id)object
调用函数
-(void)overridemethod(
custom class object1 isEqual: custom class object2
)
函数的定义
let suppose comparing the date parameter of two objects. Then how can i do that.
提前致谢
最佳答案
实现通常采用这种形式:
@interface MONInteger : NSObject
{
@private
int value;
}
@property (nonatomic, assign, readonly) int value;
@end
@implementation MONInteger
...
- (BOOL)isEqual:(id)object
{
// MONInteger allows a comparison to NSNumber
if ([object isKindOfClass:[NSNumber class]]) {
NSNumber * other = object;
return self.value == other.intValue;
}
else if (![object isKindOfClass:self.class]) {
return NO;
}
MONInteger * other = object;
return self.value == other.value;
}
@end
关于iphone - 覆盖 - (BOOL)isEqual :(id)object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8967700/