I’m going crazy right now. I have a NSMutableArray with a bunch of Person objects. I want to remove the duplicated objects but it won’t work. This is what i got:
NSMutableArray *withoutDoubles =[[NSMutableArray alloc]init];
NSArray *temp = [[NSArray alloc] initWithArray:tempResults];
for (Person *person in temp) {
if(![withoutDoubles containsObject:person]) {
[withoutDoubles addObject:person];
}
}
for (Person *person in withoutDoubles) {
NSLog(@"----> %@",person.name);
}
That is not working, i still got duplicates. I also tried:
NSArray *temp = [[NSArray alloc] initWithArray:tempResults];
NSSet *set = [NSSet setWithArray:temp];
But it didn’t work either. I need some help here.
Thanks in advance.
If your definition of a duplicate is two separate Person objects whose properties are set the same then the best way to achieve this is to override these two methods in your Person object
which will allow you to properly achieve the compare.
You would then need to do the following