iphone - 覆盖 - (BOOL)isEqual :(id)object

标签 iphone objective-c ios comparison nsobject

我想覆盖这个方法来比较两个对象。

-(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/

相关文章:

ios - 调整音量 ios

ios - SKShapeNode 选择 X 数量

ios - cordova控制台日志无法安装

iphone - Xcode:iPhone 应用程序代码设计错误

iphone - 在另一个循环中循环

ios - UICollectionView 的 cellForItemAtIndexPath 没有被调用

ios - dealloc AVCaptureVideoPreviewLayer 期间罕见崩溃

iphone - 从 modalViewController 中调用父类中的方法

ios - Swift 以编程方式转至 xib 文件

c++ - 如何访问 C++ 中的实例变量,如 Objective-C getter 和 setter