Class

NSOrderedSet

A static, ordered collection of unique objects.

Declaration

@interface NSOrderedSet<__covariant ObjectType> : NSObject

Overview

NSOrderedSet declares the programmatic interface for static sets of distinct objects. You establish a static set’s entries when it’s created, and thereafter the entries can’t be modified. NSMutableOrderedSet, on the other hand, declares a programmatic interface for dynamic sets of distinct objects. A dynamic—or mutable—set allows the addition and deletion of entries at any time, automatically allocating memory as needed.

You can use ordered sets as an alternative to arrays when the order of elements is important and performance in testing whether an object is contained in the set is a consideration—testing for membership of an array is slower than testing for membership of a set.

Topics

Creating an Ordered Set

+ orderedSet

Creates and returns an empty ordered set

+ orderedSetWithArray:

Creates and returns a set containing a uniqued collection of the objects contained in a given array.

+ orderedSetWithArray:range:copyItems:

Creates and returns a new ordered set for a specified range of objects in an array.

+ orderedSetWithObject:

Creates and returns a ordered set that contains a single given object.

+ orderedSetWithObjects:

Creates and returns a ordered set containing the objects in a given argument list.

+ orderedSetWithObjects:count:

Creates and returns a set containing a specified number of objects from a given C array of objects.

+ orderedSetWithOrderedSet:

Creates and returns an ordered set containing the objects from another ordered set.

+ orderedSetWithOrderedSet:range:copyItems:

Creates and returns a new ordered set for a specified range of objects in an ordered set.

+ orderedSetWithSet:

Creates and returns an ordered set with the contents of a set.

+ orderedSetWithSet:copyItems:

Creates and returns an ordered set with the contents of a set, optionally copying the items.

Initializing an Ordered Set

- initWithArray:

Initializes a newly allocated set with the objects that are contained in a given array.

- initWithArray:copyItems:

Initializes a newly allocated set with the objects that are contained in a given array, optionally copying the items.

- initWithArray:range:copyItems:

Initializes a newly allocated set with the objects that are contained in the specified range of an array, optionally copying the items.

- initWithObject:

Initializes a new ordered set with the object.

- initWithObjects:

Initializes a newly allocated set with members taken from the specified list of objects.

- initWithObjects:count:

Initializes a newly allocated set with a specified number of objects from a given C array of objects.

- initWithOrderedSet:

Initializes a new ordered set with the contents of a set.

- initWithOrderedSet:copyItems:

Initializes a new ordered set with the contents of a set, optionally copying the items.

- initWithOrderedSet:range:copyItems:

Initializes a new ordered set with the contents of an ordered set, optionally copying the items.

- initWithSet:

Initializes a new ordered set with the contents of a set.

- initWithSet:copyItems:

Initializes a new ordered set with the contents of a set, optionally copying the objects in the set.

- init

Initializes a newly allocated ordered set.

Counting Entries

count

The number of members in the set.

Accessing Set Members

- containsObject:

Returns a Boolean value that indicates whether a given object is present in the ordered set.

- enumerateObjectsAtIndexes:options:usingBlock:

Executes a given block using the objects in the ordered set at the specified indexes.

- enumerateObjectsUsingBlock:

Executes a given block using each object in the ordered set.

- enumerateObjectsWithOptions:usingBlock:

Executes a given block using each object in the set, using the specified enumeration options.

firstObject

The first object in the ordered set.

lastObject

The last object in the ordered set.

- objectAtIndex:

Returns the object at the specified index of the set.

- objectAtIndexedSubscript:

Returns the object at the specified index of the set.

- objectsAtIndexes:

Returns the objects in the ordered set at the specified indexes.

- indexOfObject:

Returns the index of the specified object.

- indexOfObject:inSortedRange:options:usingComparator:

Returns the index, within a specified range, of an object compared with elements in the ordered set using a given NSComparator block.

- indexOfObjectAtIndexes:options:passingTest:

Returns the index, from a given set of indexes, of the object in the ordered set that passes a test in a given block for a given set of enumeration options.

- indexOfObjectPassingTest:

Returns the index of the object in the ordered set that passes a test in a given block.

- indexOfObjectWithOptions:passingTest:

Returns the index of an object in the ordered set that passes a test in a given block for a given set of enumeration options.

- indexesOfObjectsAtIndexes:options:passingTest:

Returns the index, from a given set of indexes, of the object in the ordered set that passes a test in a given block for a given set of enumeration options.

- indexesOfObjectsPassingTest:

Returns the index of the object in the ordered set that passes a test in a given block.

- indexesOfObjectsWithOptions:passingTest:

Returns the index of an object in the ordered set that passes a test in a given block for a given set of enumeration options.

- objectEnumerator

Returns an enumerator object that lets you access each object in the ordered set.

- reverseObjectEnumerator

Returns an enumerator object that lets you access each object in the ordered set.

reversedOrderedSet

An ordered set in the reverse order.

- getObjects:range:

Copies the objects contained in the ordered set that fall within the specified range to objects.

Key-Value Coding Support

- setValue:forKey:

Invokes setValue:forKey: on each of the receiver's members using the specified value and key

- valueForKey:

Returns an ordered set containing the results of invoking valueForKey: using key on each of the ordered set’s objects.

Key-Value Observing Support

Comparing Sets

- isEqualToOrderedSet:

Compares the receiving ordered set to another ordered set.

- intersectsOrderedSet:

Returns a Boolean value that indicates whether at least one object in the receiving ordered set is also present in another given ordered set.

- intersectsSet:

Returns a Boolean value that indicates whether at least one object in the receiving ordered set is also present in another given set.

- isSubsetOfOrderedSet:

Returns a Boolean value that indicates whether every object in the receiving ordered set is also present in another given ordered set.

- isSubsetOfSet:

Returns a Boolean value that indicates whether every object in the receiving ordered set is also present in another given set.

Creating a Sorted Array

- sortedArrayUsingDescriptors:

Returns an array of the ordered set’s elements sorted as specified by a given array of sort descriptors.

- sortedArrayUsingComparator:

Returns an array that lists the receiving ordered set’s elements in ascending order, as determined by the comparison method specified by a given NSComparator block

- sortedArrayWithOptions:usingComparator:

Returns an array that lists the receiving ordered set’s elements in ascending order, as determined by the comparison method specified by a given NSComparator block.

Filtering Ordered Sets

- filteredOrderedSetUsingPredicate:

Evaluates a given predicate against each object in the receiving ordered set and returns a new ordered set containing the objects for which the predicate returns true.

Describing a Set

description

A string that represents the contents of the ordered set, formatted as a property list.

- descriptionWithLocale:

Returns a string that represents the contents of the ordered set, formatted as a property list.

- descriptionWithLocale:indent:

Returns a string that represents the contents of the ordered set, formatted as a property list.

Converting Other Collections

array

A representation of the ordered set as an array.

set

A representation of the set containing the contents of the ordered set.

Initializers

See Also

Specialized Sets

NSCountedSet

A mutable, unordered collection of distinct objects that may appear more than once in the collection.

NSMutableOrderedSet

A dynamic, ordered collection of unique objects.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software