NSMutableOrderedSet Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in OS X v10.7 and later. |
| Declared in | NSOrderedSet.h |
Overview
NSMutableOrderedSet class declares the programmatic interface to a mutable, ordered collection of distinct objects.
NSMutableOrderedSet objects are not like C arrays. That is, even though you may specify a size when you create a mutable ordered set, the specified size is regarded as a “hint”; the actual size of the set is still 0. This means that you cannot insert an object at an index greater than the current count of an set. For example, if a set contains two objects, its size is 2, so you can add objects at indices 0, 1, or 2. Index 3 is illegal and out of bounds; if you try to add an object at index 3 (when the size of the array is 2), NSMutableOrderedSet raises an exception.
Tasks
Creating a Mutable Ordered Set
Adding, Removing, and Reordering Entries
-
– addObject: -
– addObjects:count: -
– addObjectsFromArray: -
– insertObject:atIndex: -
– setObject:atIndexedSubscript: -
– insertObjects:atIndexes: -
– removeObject: -
– removeObjectAtIndex: -
– removeObjectsAtIndexes: -
– removeObjectsInArray: -
– removeObjectsInRange: -
– removeAllObjects -
– replaceObjectAtIndex:withObject: -
– replaceObjectsAtIndexes:withObjects: -
– replaceObjectsInRange:withObjects:count: -
– setObject:atIndex: -
– moveObjectsAtIndexes:toIndex: -
– exchangeObjectAtIndex:withObjectAtIndex:
Sorting Entries
Combining and Recombining Entries
Class Methods
orderedSetWithCapacity:
Creates and returns an mutable ordered set with a given initial capacity.
Parameters
- numItems
The initial capacity of the new ordered set.
Return Value
A mutable ordered set with initial capacity to hold numItems members.
Discussion
Mutable ordered sets allocate additional memory as needed, so numItems simply establishes the set’s initial capacity.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hInstance Methods
addObject:
Appends a given object to the mutable ordered set, if it is not already a member.
Parameters
- object
The object to add to the set.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.haddObjects:count:
Appends the given number of objects from a given C array.
Parameters
- objects
A C array of objects.
- count
The number of values from the objects C array to append to the mutable ordered set. This number will be the count of the new array—it must not be negative or greater than the number of elements in objects.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.haddObjectsFromArray:
Appends to the mutable ordered 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 OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hexchangeObjectAtIndex:withObjectAtIndex:
Exchanges the object at the specified index with the object at the other index.
Parameters
- idx1
The index of the first object.
Important: Raises an
NSRangeExceptionif index is beyond the end of the mutable ordered set.- idx2
The index of the second object.
Important: Raises an
NSRangeExceptionif index is beyond the end of the mutable ordered set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hinitWithCapacity:
Returns an initialized mutable ordered set with a given initial capacity.
Parameters
- numItems
The initial capacity of the new ordered set.
Return Value
An initialized mutable ordered set with initial capacity to hold numItems members.
Discussion
Mutable ordered sets allocate additional memory as needed, so numItems simply establishes the set’s initial capacity.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hinsertObject:atIndex:
Inserts the given object at the specified index of the mutable ordered set.
Parameters
- object
The object to insert into to the set’s content. This value must not be
nil.Important: Important: Raises an
NSInvalidArgumentExceptionif object isnil.- idx
The index in the mutable ordered set at which to insert object. This value must not be greater than the count of elements in the array.
Important: Important: Raises an
NSRangeExceptionifidxis greater than the number of elements in the mutable ordered set.
Discussion
If the index is already occupied, the objects at index and beyond are shifted by adding 1 to their indices to make room.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hinsertObjects:atIndexes:
Inserts the objects in the array at the specified indexes.
Parameters
- objects
An array of objects to insert into the mutable ordered set.
- indexes
The indexes at which the objects in objects should be inserted. The count of locations in indexes must equal the count of objects.
Discussion
Each object in objects is inserted into the receiving mutable ordered set in turn at the corresponding location specified in indexes after earlier insertions have been made.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hintersectOrderedSet:
Removes from the receiving ordered set each object that isn’t a member of another ordered set.
Parameters
- other
The ordered set with which to perform the intersection.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hintersectSet:
Removes from the receiving ordered set each object that isn’t a member of another set.
Parameters
- other
The set with which to perform the intersection.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hminusOrderedSet:
Removes each object in another given ordered set from the receiving mutable ordered set, if present.
Parameters
- other
The ordered set of objects to remove from the receiving set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hminusSet:
Removes each object in another given set from the receiving mutable ordered set, if present.
Parameters
- other
The set of objects to remove from the receiving set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hmoveObjectsAtIndexes:toIndex:
Moves the object at the specified indexes to the new location.
Parameters
- indexes
The indexes of the objects to move.
- idx
The index in the mutable ordered array at which to insert the objects.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hremoveAllObjects
Removes all the objects from the mutable ordered set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hremoveObject:
Removes a given object from the mutable ordered set.
Parameters
- object
The object to remove from the mutable ordered set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hremoveObjectAtIndex:
Removes a the object at the specified index from the mutable ordered set.
Parameters
- idx
The index of the object to remove from the mutable ordered set. The value must not exceed the bounds of the set.
Important: Raises an
NSRangeExceptionif index is beyond the end of the mutable ordered set.
Discussion
To fill the gap, all elements beyond index are moved by subtracting 1 from their index.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hremoveObjectsAtIndexes:
Removes the objects at the specified indexes from the mutable ordered set.
Parameters
- indexes
The indexes of the objects to remove from the mutable ordered set. The locations specified by indexes must lie within the bounds of the mutable ordered .
Discussion
This method is similar to removeObjectAtIndex:, but allows you to efficiently remove multiple objects with a single operation.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hremoveObjectsInArray:
Removes the objects in the array from the mutable ordered set.
Parameters
- array
An array containing the objects to be removed from the receiving mutable ordered set.
Discussion
This method is similar to removeObject:, but allows you to efficiently remove large sets of objects with a single operation. If the receiving mutable ordered set does not contain objects in array, the method has no effect (although it does incur the overhead of searching the contents).
This method assumes that all elements in array respond to hash and isEqual:.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hremoveObjectsInRange:
Removes from the mutable ordered set each of the objects within a given range.
Parameters
- range
The range of the objects to remove from the mutable ordered set.
Discussion
The objects are removed using removeObjectAtIndex:.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hreplaceObjectAtIndex:withObject:
Replaces the object at the specified index with the new object.
Parameters
- idx
The index of the object to be replaced. This value must not exceed the bounds of the mutable ordered set.
Important: Raises an
NSRangeExceptionif index is beyond the end of the mutable ordered set.- object
The object with which to replace the object at the index in the ordered set specified by
idx. This value must not benil.Important: Raises an
NSInvalidArgumentExceptionif object isnil.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hreplaceObjectsAtIndexes:withObjects:
Replaces the objects at the specified indexes with the new objects.
Parameters
- indexes
The indexes of the objects to be replaced.
- objects
The objects with which to replace the objects in the receiving mutable ordered set at the indexes specified by indexes.
The count of locations in indexes must equal the count of objects.
Discussion
The indexes in indexes are used in the same order as the objects in objects.
If objects or indexes is nil, this method raises an exception.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hreplaceObjectsInRange:withObjects:count:
Replaces the objects in the receiving mutable ordered set at the range with the specified number of objects from a given C array.
Parameters
- range
The range of the objects to replace.
- objects
A C array of objects.
- count
The number of values from the objects C array to insert in place of the objects in range. This number will be the count of the new array—it must not be negative or greater than the number of elements in objects.
Discussion
Elements are added to the new array in the same order they appear in objects, up to but not including index count.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hsetObject:atIndex:
Appends or replaces the object at the specified index.
Parameters
- obj
The object to insert or append.
- idx
The index. If the index is equal to the length of the collection, then it inserts the object at that index, otherwise it replaces the object at that index with the given object.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hsetObject:atIndexedSubscript:
Inserts the given object at the specified index of the mutable ordered set.
Parameters
- object
The object to insert into to the set’s content. This value must not be
nil.Important: Important: Raises an
NSInvalidArgumentExceptionif object isnil.- idx
The index in the mutable ordered set at which to insert object. This value must not be greater than the count of elements in the array.
Important: Important: Raises an
NSRangeExceptionifidxis greater than the number of elements in the mutable ordered set.
Discussion
If the index is already occupied, the objects at index and beyond are shifted by adding 1 to their indices to make room.
This method is identical to insertObject:atIndex:.
Availability
- Available in OS X v10.8 and later.
Declared In
NSOrderedSet.hsortRange:options:usingComparator:
Sorts the specified range of the mutable ordered set using the specified options and the comparison method specified by a given comparator block.
Parameters
- range
The range to sort.
- opts
A bitmask that specifies the options for the sort (whether it should be performed concurrently and whether it should be performed stably).
- cmptr
A comparator block.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hsortUsingComparator:
Sorts the mutable ordered set using the comparison method specified by the comparator block.
Parameters
- cmptr
A comparator block.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hsortWithOptions:usingComparator:
Sorts the mutable ordered set using the specified options and the comparison method specified by a given comparator block.
Parameters
- opts
A bitmask that specifies the options for the sort (whether it should be performed concurrently and whether it should be performed stably).
- cmptr
A comparator block.
Availability
- Available in OS X v10.7 and later.
Declared In
NSOrderedSet.hunionOrderedSet:
Adds each object in another given ordered set to the receiving mutable ordered set, if not present.
Parameters
- other
The set of objects to add to the receiving mutable ordered set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.hunionSet:
Adds each object in another given set to the receiving mutable ordered set, if not present.
Parameters
- other
The set of objects to add to the receiving mutable ordered set.
Availability
- Available in OS X v10.7 and later.
See Also
Declared In
NSOrderedSet.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)