I am checking if my one of the array consist the Nsobject
which i have created custom way.
i am using ContainsObject
method.my problem is that contains object not working ever.even though i have same object in array its not returning the true value.
if([self.arrSelectedInterest containsObject:interest_ent])
i am also attaching the screen shot of my debug points which showing the value of the nsarray and comparing object and in that i found that interest_ent
is a same object that contains in self.arrSelectedInterest
and still it always return false.
anyone have any idea how to check if my nsarray of custom nsobject contains specific Object?
Following is my hash and isEqual Method which i have overriden and also shwoing my property types in nsobejct. @interface InterestEntity : JSONModel
@property (strong, nonatomic) NSString* InterestId;
@property (strong, nonatomic) NSString* Name;
@property (strong, nonatomic) NSString<Optional>* Code;
@property (strong, nonatomic) NSString<Optional>* Description;
@property (strong, nonatomic) NSArray<Optional>* Hashtags;
- (NSUInteger)hash {
NSUInteger result = 1;
NSUInteger prime = 31;
result = prime * result + [self.InterestId hash];
result = prime * result + [self.Name hash];
result = prime * result + [self.Code hash];
result = prime * result + [self.Description hash];
result = prime * result + [self.Hashtags hash];
return result;
}
- (BOOL)isEqual:(id)object {
BOOL result = NO;
if ([object isKindOfClass:[self class]]) {
result = [[self InterestId] isEqualToString:[object InterestId]] &&
[[self Name] isEqualToString:[object Name]] &&
[[self Code] isEqualToString:[object Code]] &&[[self Description] isEqualToString:[object Description]] && [[self Hashtags] isEqual:[object Hashtags]];
}
return result;
}