• 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 NSMutableSet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Counting NSMutableSet


  • Subject: Counting NSMutableSet
  • From: "Mark Hill" <email@hidden>
  • Date: Tue, 15 May 2007 12:45:47 +0100

Is there an efficient way of identifying the number of elements in an
NSMutableSet. The count function only returns the "uniqueness" of
members rather than the total.

At the moment I'm using an enumerator with an accumulating int, thus:

	NSMutableSet *mySet;
	mySet = [self mutableSetValueForKey: @"Entity"];

	NSEnumerator *enumerator = [mySet objectEnumerator];

	id value;
	int count = 0;

	while ((value = [enumerator nextObject])) {
		count++;
	}
	NSLog(@"elements in set %i", count);
}

But this seems rather expensive to my mind. Surely there's a more efficient way?

Thanks.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Counting NSMutableSet
      • From: "Clark Cox" <email@hidden>
  • Prev by Date: Re: Unique items in Core Data models
  • Next by Date: re:Counting NSMutableSet
  • Previous by thread: Re: NSDictionary valueForKey: and @ character at start of NSString
  • Next by thread: Re: Counting NSMutableSet
  • Index(es):
    • Date
    • Thread