Return to the Alphabetic Index
Return to the Class Browser
Return to the Picture Browser
Copyright (c) 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 considerationwhile 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 set1/4 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 init1/4 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

Adding Objects

Removing Objects