Class

NSMutableSet

A dynamic unordered collection of unique objects.

Declaration

@interface NSMutableSet<__covariant ObjectType> : NSSet

Overview

The NSMutableSet class declares the programmatic interface to a mutable, unordered collection of distinct objects.

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.

NSMutableSet is “toll-free bridged” with its Core Foundation counterpart, CFMutableSetRef. See Toll-Free Bridging for more information.

Subclassing Notes

There should be little need of subclassing. If you need to customize behavior, it is often better to consider composition instead of subclassing.

Methods to Override

In a subclass, you must override both of its primitive methods:

You must also override the primitive methods of the NSSet class.

Topics

Creating a mutable set

+ setWithCapacity:

Creates and returns a mutable set with a given initial capacity.

- initWithCapacity:

Returns an initialized mutable set with a given initial capacity.

- init

Initializes a newly allocated set.

Adding and removing entries

- addObject:

Adds a given object to the set, if it is not already a member.

- filterUsingPredicate:

Evaluates a given predicate against the set’s content and removes from the set those objects for which the predicate returns false.

- removeObject:

Removes a given object from the set.

- removeAllObjects

Empties the set of all of its members.

- addObjectsFromArray:

Adds to the set each object contained in a given array that is not already a member.

Combining and recombining sets

- unionSet:

Adds each object in another given set to the receiving set, if not present.

- minusSet:

Removes each object in another given set from the receiving set, if present.

- intersectSet:

Removes from the receiving set each object that isn’t a member of another given set.

- setSet:

Empties the receiving set, then adds each object contained in another given set.

Initializers

Relationships

Inherits From

See Also

Basic Collections

NSArray

A static ordered collection of objects.

NSMutableArray

A dynamic ordered collection of objects.

NSDictionary

A static collection of objects associated with unique keys.

NSMutableDictionary

A dynamic collection of objects associated with unique keys.

NSSet

A static unordered collection of unique objects.