Mac 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. More...

Inheritance


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • 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.

    Import Statement

    Availability

    Available in OS X v10.0 and later.

  • init(capacity:) initWithCapacity: Designated Initializer

    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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.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.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.9 and later.

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

    Declaration

    Swift

    func addObject(_ object: AnyObject)

    Objective-C

    - (void)addObject:(id)object

    Parameters

    object

    The object to add to the set.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func filterUsingPredicate(_ predicate: NSPredicate)

    Objective-C

    - (void)filterUsingPredicate:(NSPredicate *)predicate

    Parameters

    predicate

    A predicate.

    Discussion

    The following example illustrates the use of this method.

    • NSMutableSet *mutableSet =
    • [NSMutableSet setWithObjects:@"One", @"Two", @"Three", @"Four", nil];
    • NSPredicate *predicate =
    • [NSPredicate predicateWithFormat:@"SELF beginswith 'T'"];
    • [mutableSet filterUsingPredicate:predicate];
    • // mutableSet contains (Two, Three)

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.5 and later.

  • Removes a given object from the set.

    Declaration

    Swift

    func removeObject(_ object: AnyObject)

    Objective-C

    - (void)removeObject:(id)object

    Parameters

    object

    The object to remove from the set.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Empties the set of all of its members.

    Declaration

    Swift

    func removeAllObjects()

    Objective-C

    - (void)removeAllObjects

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func addObjectsFromArray(_ array: [AnyObject])

    Objective-C

    - (void)addObjectsFromArray:(NSArray *)array

    Parameters

    array

    An array of objects to add to the set.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func unionSet(_ otherSet: NSSet)

    Objective-C

    - (void)unionSet:(NSSet *)otherSet

    Parameters

    otherSet

    The set of objects to add to the receiving set.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func minusSet(_ otherSet: NSSet)

    Objective-C

    - (void)minusSet:(NSSet *)otherSet

    Parameters

    otherSet

    The set of objects to remove from the receiving set.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func intersectSet(_ otherSet: NSSet)

    Objective-C

    - (void)intersectSet:(NSSet *)otherSet

    Parameters

    otherSet

    The set with which to perform the intersection.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

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

    Declaration

    Swift

    func setSet(_ otherSet: NSSet)

    Objective-C

    - (void)setSet:(NSSet *)otherSet

    Parameters

    otherSet

    The set whose members replace the receiving set's content.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.