Copyright ã1994 by NeXT Computer, Inc.  All Rights Reserved.

NSMutableSet 

Inherits From:	NSSet : NSObject

Conforms To:	NSCoding, NSCopying, NSMutableCopying (NSSet)
NSObject (NSObject)

Declared In:	Foundation/NSSet.h 

Class Description

The NSMutableSet class declares the programmatic interface to an object that manages a mutable set of objects. NSMutableSet provides support for the mathematical concept of a set. A set, both in its mathematical sense, and in the OpenStep implementation of NSMutableSet, is an unordered collection of distinct elements. OpenStep also provides the NSCountedSet class for a mutable set that can contain multiple instances of the same element, and provides the NSSet class for creating and managing immutable sets. In general, you should use NSSet unless you really need a mutable set.

Use set objects as an alternative to array objects when the order of elements is not important, but performance in testing whether an object is contained in the set is a considerationÐwhile arrays are ordered, testing for membership is slower than with sets.

Objects in a set must respond to hash and isEqual: methods. See the NSObject protocol for details on hash and isEqual:.

Generally, you instantiate an NSMutableSet object by sending one of the set¼ methods to the NSMutableSet class object, as described in the method descriptions for NSSet. These methods return an NSMutableSet object containing the elements (if any) you pass in as arguments. Newly created instances of NSMutableSet created by invoking the set method can be populated with objects using any of the init¼ methods. initWithObjects:: is the designated initializer for this class.

Objects are added to an NSMutableSet using addObject:, which adds a single specified object to the set, addObjectsFromArray:, which adds all objects from a specified array to the set, or by unionSet:, which adds all the objects from another set to this set.

Objects are removed from an NSMutableSet using any of the methods intersectSet:, minusSet:, removeAllObjects	, or removeObject:.

Allocating and Initializing an NSMutableSet

+ (id)allocWithZone:(NSZone *)zone	Creates and returns an uninitialized set object in zone.

+ (id)setWithCapacity:(unsigned)numItems	Creates and returns a set object, giving it enough allocated memory to hold numItems objects.

- (id)initWithCapacity:(unsigned)numItems	Initializes a newly allocated set object, giving it enough allocated memory to hold numItems objects.

Adding Objects	

- (void)addObject:(id)object	Adds object to the set, unless object is equal to some object already in the set.

- (void)addObjectsFromArray:(NSArray *)array	Adds to the set all the objects in array, by calling addObject: for each one.

- (void)unionSet:(NSSet *)other 	Adds to the receiving set all the objects in other, by calling addObject: for each one.

Removing Objects

- (void)intersectSet:(NSSet *)other	Removes from the receiving set every object that's not equal to any object in other, by calling removeObject: for each one.

- (void)minusSet:(NSSet *)other	Removes from the receiving set every object that's equal to some object in other, by calling removeObject: for each one.

- (void)removeAllObjects	Empties the set of all its elements. (This method doesn't call removeObject:.)

- (void)removeObject:(id)object	If any member of the receiving set is equal to object, this method removes that object from the set.