O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSCountedSet — Mac OS X 10.0

Synopsis

This class extends the functionality of NSMutableSet by associating with each member of the set a count of how many times the object has been added to the set. By keeping a count with each object, NSCountedSet essentially removes the restriction that every member of a set must be unique. NSCountedSet reimplements several of NSMutableSet’s methods to support the object counter. The one new method in NSCountedSet is countForObject:, which will return the counter value for the specified object. If the object is not a member of the set, this method returns 0. This count can be viewed as the number of occurences of the object within the set.

image with no caption

@interface NSCountedSet : NSMutableSet
                                  // Initializers
   - (id)initWithArray:(NSArray *)array;
   - (id)initWithCapacity:(unsigned)numItems;
   - (id)initWithSet:(NSSet *)set;
                                  // Instance Methods
   - (void)addObject:(id)object;
   - (unsigned)countForObject:(id)object;
   - (NSEnumerator *)objectEnumerator;
   - (void)removeObject:(id)object;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required