I am trying to remove any duplicates from my sorted array... I thought I could do it using an example from another question of mine but it turns out to not even come close to working.
its a pretty horrible attempt, but its the only way i can figure out how to compare two elements of a single item(NSDictionary) in a NSMutableArray.
Here is my code example
I currently have a sorted array
NSArray *duplicatesRemovedArray = [sortedArray sortedArrayUsingComparator:^NSComparisonResult(id a, id b) {
NSDictionary *dictA = a;
NSDictionary *dictB = b;
NSString *startYear1 = dictA[kStartYear];
NSString *finishYear1 = dictA[kFinishYear];
NSString *allYear1 = [NSString stringWithFormat:@"%@%@",startYear1, finishYear1];
NSString *startYear2 = dictB[kStartYear];
NSString *finishYear2 = dictB[kFinishYear];
NSString *allYear2 = [NSString stringWithFormat:@"%@%@",startYear2, finishYear2];
return [allYear1 compare:allYear2];
}];
if anyone has any ideas on how to create an NSArray of unique items that is what I am after, if you could give me any suggestions, code examples that would be greatly appreciated
Update: I should point out that my NSDictionary has another element within it an ID...
so I cannot just compare objects like in the examples you have listed... this was an oversight on my part. So effectivly the objects look like this
ID: 1234
STARTYEAR: 1999
FINISHYEAR: 2000
so I need some help removing objects whos StartYear and FinishYear match other objects start and finish year.