重写isEqual方法和hush方法

//重写isEqual方法

- (BOOL)isEqual:(id)object {

   

    if (self == object) {

        return YES;

    }

    if (object ==nil){

        return NO;

    }

    if (![object isKindOfClass:[BookModal class]]) {

        return NO;

    }

    BookModal *other = object;

    return other.bookId != nil && [other.bookId isEqual:_bookId];

 

}

 

- (NSUInteger)hash{

    int prime = 31;

    long result = 1;

    result = prime * result + ((self.bookId == nil) ? 0 : self.bookId.hash);

    return result;

}

你可能感兴趣的:(ios,object,hash,isEqual)