NSMutableSet Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in iOS 2.0 and later. |
| Companion guide | |
| Declared in | NSPredicate.h NSSet.h |
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.
Class Methods
setWithCapacity:
Creates and returns a mutable set with a given initial capacity.
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.
See Also
-
– initWithCapacity: -
set(NSSet) -
setWithObjects:count:(NSSet)
Declared In
NSSet.hInstance Methods
addObject:
Adds a given object to the set, if it is not already a member.
Parameters
- object
The object to add to the set.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.haddObjectsFromArray:
Adds to the set each object contained in a given array that is not already a member.
Parameters
- array
An array of objects to add to the set.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.hfilterUsingPredicate:
Evaluates a given predicate against the set’s content and removes from the set those objects for which the predicate returns false.
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) |
Availability
- Available in iOS 3.0 and later.
Declared In
NSPredicate.hinitWithCapacity:
Returns an initialized mutable set with a given initial capacity.
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.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.hintersectSet:
Removes from the receiving set each object that isn’t a member of another given set.
Parameters
- otherSet
The set with which to perform the intersection.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.hminusSet:
Removes each object in another given set from the receiving set, if present.
Parameters
- otherSet
The set of objects to remove from the receiving set.
Availability
- Available in iOS 2.0 and later.
Declared In
NSSet.hremoveAllObjects
Empties the set of all of its members.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.hremoveObject:
Removes a given object from the set.
Parameters
- object
The object to remove from the set.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.hsetSet:
Empties the receiving set, then adds each object contained in another given set.
Parameters
- otherSet
The set whose members replace the receiving set's content.
Availability
- Available in iOS 2.0 and later.
Declared In
NSSet.hunionSet:
Adds each object in another given set to the receiving set, if not present.
Parameters
- otherSet
The set of objects to add to the receiving set.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSSet.h© 2010 Apple Inc. All Rights Reserved. (Last updated: 2010-08-17)