iOS Developer Library

Developer

Foundation Framework Reference NSMutableSet Class Reference

Options
Deployment Target:

On This Page
Language:

NSMutableSet

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.

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

    Declaration

    Objective-C

    + (instancetype)setWithCapacity:(NSUInteger)numItems

    Parameters

    numItems

    The initial capacity of the new set.

    Return Value

    A mutable set with initial capacity to hold numItems members.

    Discussion

    Mutable sets allocate additional memory as needed, so numItems simply establishes the object’s initial capacity.

    Availability

    Available in iOS 2.0 and later.

  • Returns an initialized mutable set with a given initial capacity.

    Declaration

    Swift

    init(capacity numItems: Int)

    Objective-C

    - (instancetype)initWithCapacity:(NSUInteger)numItems

    Parameters

    numItems

    The initial capacity of the set.

    Return Value

    An initialized mutable set with initial capacity to hold numItems members. The returned set might be different than the original receiver.

    Discussion

    Mutable sets allocate additional memory as needed, so numItems simply establishes the object’s initial capacity.

    This method is a designated initializer for NSMutableSet.

    Availability

    Available in iOS 2.0 and later.

  • init() - init Designated Initializer

    Initializes a newly allocated set.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    A set.

    Discussion

    This method is a designated initializer of NSMutableSet.

    Availability

    Available in iOS 7.0 and later.