counting objects in array
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.