I have this problem with removing duplicate objects from an array.
I tried these already:
noDuplicates = _personalHistory.personalHistory;
for (int i=[noDuplicates count]-1; i>0; i--) {
if ([noDuplicates indexOfObject: [noDuplicates objectAtIndex: i]]<i)
[noDuplicates removeObjectAtIndex: i];
}
for (PersonalHistory_artikels *e in _personalHistory.personalHistory) {
if (![noDuplicates containsObject:e]) {
NSLog(@"Dubplicates");
[noDuplicates addObject:e];
}
}
for (i=0; i<_personalHistory.personalHistory.count; i++) {
PersonalHistory_artikels *test = [_personalHistory.personalHistory objectAtIndex:i];
for (j=0; j<_personalHistory.personalHistory.count; j++) {
PersonalHistory_artikels *test2 = [_personalHistory.personalHistory objectAtIndex:j];
if (! [test.nieuwsTITLE_personal isEqual:test2.nieuwsTITLE_personal]) {
NSLog(@"Add test = %@", test.nieuwsTITLE_personal);
[noDuplicates addObject:test];
}
}
}
But none of the above gave me the right array. The last one was the best, but it still showed duplicate values. Can someone help me with this problem?
Thank you very much.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…