Re: Deleting duplicates in NSMutableArray
Re: Deleting duplicates in NSMutableArray
- Subject: Re: Deleting duplicates in NSMutableArray
- From: Johan Kool <email@hidden>
- Date: Mon, 5 Jul 2004 00:20:41 +0200
Grmbl.... as always, that one clear moment comes right after pressing
that "Send" button...
For the archives, this should do it:
// Delete duplicates
for (i=0; i < [mutArray count]; i++ ) {
for (j=(i+1); j < [mutArray count]; j++) {
if ([[mutArray objectAtIndex:i] isEqualTo:[mutArray
objectAtIndex:j]]) {
[mutArray removeObjectAtIndex:j];
j--; // everything shifts down, so at j there is now an
entry we haven't yet checked
}
}
}
Talking about archives, any news on mamasam?
Bye,
Johan
Hi all,
I am a bit stuck with this piece of code that has to remove duplicate
NSStrings from a NSMutableArray. It fails when multiple duplicates
come right after each other in the array. It has to do something with
shifting indexes when an object is deleted, but can't think of how to
solve it.
// Delete duplicates
for (i=0; i < [mutArray count]; i++ ) {
for (j=(i+1); j < [mutArray count]; j++) {
if ([[mutArray objectAtIndex:i] isEqualTo:[mutArray
objectAtIndex:j]]) {
[mutArray removeObjectAtIndex:j];
}
}
}
What do I do wrong?!
Thanks already!
Johan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.