• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Deleting duplicates in NSMutableArray
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Deleting duplicates in NSMutableArray


  • Subject: Re: Deleting duplicates in NSMutableArray
  • From: Stéphane Sudre <email@hidden>
  • Date: Mon, 5 Jul 2004 00:40:35 +0200

On lundi, juillet 5, 2004, at 12:20 AM, Johan Kool wrote:

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
}
}
}

Some suggestions because your code is not really optimized.

int tCount;

tCount= [mutArray count];

for (i=0; i < tCount; i++ )
{
id tObjectToLookFor;

tObjectToLookFor= [mutArray objectAtIndex:i];

for (j=(i+1); j < tCount; j++)
{
if ([tObjectToLookFor isEqualTo:[mutArray objectAtIndex:j]])
{
[mutArray removeObjectAtIndex:j];
j--; // everything shifts down, so at j there is now an entry we haven't yet checked
tCount--;
}
}
}

Hope it helps.
_______________________________________________
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.


  • Follow-Ups:
    • Re: Deleting duplicates in NSMutableArray
      • From: Darkshadow <email@hidden>
References: 
 >Re: Deleting duplicates in NSMutableArray (From: Johan Kool <email@hidden>)

  • Prev by Date: Re: Newbie: I can't see what is wrong?
  • Next by Date: Re: Change value of NSNumber?
  • Previous by thread: Re: Deleting duplicates in NSMutableArray
  • Next by thread: Re: Deleting duplicates in NSMutableArray
  • Index(es):
    • Date
    • Thread