• 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
counting objects in array
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

counting objects in array


  • Subject: counting objects in array
  • From: Koen van der Drift <email@hidden>
  • Date: Mon, 19 Jul 2004 21:10:40 -0400

Hi,

I came up with the following code to count the occurences of objects in an array. In this snippet I count the names of the persons in an array (how many Micks, Keiths, Charlies, etc) It works, but I was wondering if this is a 'good' approach.

while (person = [enumerator nextObject])
{
aName = [person name];

if ( nil == [[tempDict allKeys] containsObject: aName] ) {
// first occurance
count = [NSNumber numberWithInt:1];
}
else
{
count = [NSNumber numberWithInt: ([[tempDict objectForKey: aName] intValue] + 1)];
}

[tempDict setObject: count forKey: aName];
}



thanks,

- Koen.
_______________________________________________
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: counting objects in array
      • From: Jonathan Jackel <email@hidden>
  • Prev by Date: Re: Finding out size of NSBitmapImageRep data pointer?
  • Next by Date: Re: Open Recent menu
  • Previous by thread: Re: NSTextField changing first responder on return key not working
  • Next by thread: Re: counting objects in array
  • Index(es):
    • Date
    • Thread