PATH  Documentation > Mac OS X > Foundation Reference: Objective-C



Table of Contents

NSMutableSet


Inherits from:
NSSet : NSObject
Conforms to:
NSCoding
(NSSet)
NSCopying (NSSet)
NSMutableCopying (NSSet)
NSObject (NSObject)
Declared in:
Foundation/NSSet.h



Class at a Glance


An NSMutableSet object stores a modifiable set of objects.

Principal Attributes


Creation



+ setWithCapacity:: Returns an empty set with enough allocated memory to hold a specified number of objects.
- initWithCapacity: Returns an empty set with enough allocated memory to hold a specified number of objects.

Commonly Used Methods



- addObject:: Adds an object to the set, if it isn't already a member.
- removeObject:: Removes an object from the set.

Primitive Methods



- addObject:: Adds an object to the set, if it isn't already a member.
- removeObject:: Removes an object from the set.




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 NSMutableSet implementation, is an unordered collection of distinct elements. The NSCountedSet class, which is a concrete subclass of NSMutableSet, supports mutable sets that can contain multiple instances of the same element. The NSSet class supports creating and managing immutable sets.

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

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




Method Types


Creating an NSMutableSet
- setWithCapacity:
- initWithCapacity:
Adding and removing entries
- addObject:
- removeObject:
- removeAllObjects
- addObjectsFromArray:
Combining and recombining sets
- unionSet:
- minusSet:
- intersectSet:
- setSet:


Class Methods



setWithCapacity:

+ (id)setWithCapacity:(unsigned)numItems

Creates and returns a mutable set, giving it enough allocated memory to hold numItems members. Mutable sets allocate additional memory as needed, so numItems simply establishes the object's initial capacity.

See Also: - initWithCapacity:, + set (NSSet), + setWithObjects:count: (NSSet)




Instance Methods



addObject:

- (void)addObject:(id)anObject

Adds the specified object to the receiver if it is not already a member. anObject is sent a retain message as it is added to the receiver. If anObject is already present in the set, this method has no effect on either the set or on anObject.

See Also: - addObjectsFromArray:, - unionSet:



addObjectsFromArray:

- (void)addObjectsFromArray:(NSArray *)anArray

Adds each object contained in anArray to the receiver, if that object is not already a member. The new member is retained. If a given element of the array is already present in the set, this method has no effect on either the set or on the array element.

See Also: - addObject:, - unionSet:



initWithCapacity:

- (id)initWithCapacity:(unsigned)numItems

Initializes a newly allocated mutable set, giving it enough allocated memory to hold numItems members. Mutable sets allocate additional memory as needed, so numItems simply establishes the object's initial capacity. Returns self.

See Also: + setWithCapacity:



intersectSet:

- (void)intersectSet:(NSSet *)otherSet

Removes from the receiver each object that isn't a member of otherSet. Each object that's removed from the receiver is sent a release message.

See Also: - removeObject:, - removeAllObjects, - minusSet:



minusSet:

- (void)minusSet:(NSSet *)otherSet

Removes from the receiver each object contained in otherSet that is also present in the receiver. Each object that's successfully removed from the receiver is sent a release message. If any member of otherSet isn't present in the receiving set, this method has no effect on either the receiver or on the otherSet member.

See Also: - removeObject:, - removeAllObjects, - intersectSet:



removeAllObjects

- (void)removeAllObjects

Empties the set of all of its members. Each member is sent a release message.

See Also: - removeObject:, - minusSet:, - intersectSet:



removeObject:

- (void)removeObject:(id)anObject

Removes anObject from the set. The removed object is sent a release message if it was a member of the receiver.

See Also: - removeObject:, - minusSet:, - intersectSet:



setSet:

- (void)setSet:(NSSet *)otherSet

Empties the receiver, then adds each object contained in otherSet to the receiver The new member is sent a retain message as it is added to the receiver.



unionSet:

- (void)unionSet:(NSSet *)otherSet

Adds each object contained in otherSet to the receiver, if that object is not already a member. The new member is sent a retain message as it is added to the receiver. If any member of otherSet is already present in the receiver, this method has no effect on either the receiver or on the otherSet member.

See Also: - addObject:, - addObjectsFromArray:




Table of Contents