NSOrderedSet Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in OS X v10.7 and later.
Declared in
NSKeyValueCoding.h
NSKeyValueObserving.h
NSOrderedSet.h
NSPredicate.h
NSSortDescriptor.h

Overview

NSOrderedSet and its subclass, NSMutableOrderedSet, declare the programmatic interfaces to an ordered collection of objects.

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.

Tasks

Creating an Ordered Set

Initializing an Ordered Set

Counting Entries

Accessing Set Members

Key-Value Coding Support

Key-Value Observing Support

Comparing Sets

Creating a Sorted Array

Filtering Ordered Sets

Describing a Set

Converting Other Collections

Class Methods

orderedSet

Creates and returns an empty ordered set

+ (instancetype)orderedSet
Return Value

A new empty ordered set.

Discussion

This method is declared primarily for the use of mutable subclasses of NSOrderedSet.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithArray:

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

+ (instancetype)orderedSetWithArray:(NSArray *)array
Parameters
array

An array containing the objects to add to the new ordered set. If the same object appears more than once in array, it is added only once to the returned set.

Return Value

A new ordered set containing a uniqued collection of the objects contained in array.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithArray:range:copyItems:

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

+ (instancetype)orderedSetWithArray:(NSArray *)array range:(NSRange)range copyItems:(BOOL)flag
Parameters
array

The array

range

The range of the objects to add to the ordered set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

A new ordered set containing a uniqued collection of the objects contained in the specified range of the array.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithObject:

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

+ (instancetype)orderedSetWithObject:(id)object
Parameters
object

The object to add to the new set.

Return Value

A new ordered set containing object.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithObjects:

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

+ (instancetype)orderedSetWithObjects:(id)firstObj,, ...
Parameters
firstObj,

The first object to add to the new set.

...

A comma-separated list of objects, ending with nil, to add to the new set.

If the same object appears more than once in the list of objects, it is added only once to the returned set. The objects are added to the ordered set in the order that they are listed.

Return Value

A new ordered set containing the objects in the argument list.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithObjects:count:

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

+ (instancetype)orderedSetWithObjects:(const id [])objects count:(NSUInteger)cnt
Parameters
objects

A C array of objects to add to the new ordered set.

If the same object appears more than once in objects, it is added only once to the returned ordered set. Each object receives a retain message as it is added to the set.

cnt

The number of objects from objects to add to the new set.

Return Value

A new ordered set containing cnt objects from the list of objects specified by objects.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithOrderedSet:

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

+ (instancetype)orderedSetWithOrderedSet:(NSOrderedSet *)set
Parameters
set

A set containing the objects to add to the new ordered set.

The objects are not copied, simply referenced.

Return Value

A new ordered set containing the objects from set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithOrderedSet:range:copyItems:

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

+ (instancetype)orderedSetWithOrderedSet:(NSOrderedSet *)set range:(NSRange)range copyItems:(BOOL)flag
Parameters
set

An ordered set.

range

The range of objects in set to add to the ordered set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

A new ordered set containing a uniqued collection of the objects contained in the specified range of the the ordered set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithSet:

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

+ (instancetype)orderedSetWithSet:(NSSet *)set
Parameters
set

A set.

Return Value

A new ordered set containing a uniqued collection of the objects contained in the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

orderedSetWithSet:copyItems:

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

+ (instancetype)orderedSetWithSet:(NSSet *)set copyItems:(BOOL)flag
Parameters
set

A set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

A new ordered set containing a uniqued collection of the objects contained in the specified range of the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

Instance Methods

addObserver:forKeyPath:options:context:

Raises an exception.

- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
Parameters
observer

The object to register for KVO notifications.

keyPath

The key path, relative to the array, of the property to observe. This value must not be nil.

options

A combination of NSKeyValueObservingOptions values that specifies what is included in observation notifications.

context

Arbitrary data that is passed to observer in observeValueForKeyPath:ofObject:change:context:.

Discussion

NSOrderedSet objects are not observable, so this method raises an exception when invoked on an NSOrderedSet object. Instead of observing an ordered set, observe the to-many relationship for which the ordered set is the collection of related objects.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSKeyValueObserving.h

array

Returns a representation of the ordered set as an array.

- (NSArray *)array
Return Value

An array containing the ordered set’s elements.

Discussion

This return a proxy object for the receiving ordered set, which acts like an immutable array.

While you cannot mutate the ordered set through this proxy, mutations to the original ordered set will be reflected in the proxy and it will appear to change spontaneously, since a copy of the ordered set is not being made.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

containsObject:

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

- (BOOL)containsObject:(id)object
Parameters
object

The object for which to test membership of the ordered set.

Return Value

YES if object is present in the set, otherwise NO.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

count

Returns the number of members in the set.

- (NSUInteger)count
Return Value

The number of members in the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

description

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

- (NSString *)description
Return Value

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

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

descriptionWithLocale:

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

- (NSString *)descriptionWithLocale:(id)locale
Parameters
locale

An NSLocale object or an NSDictionary object that specifies options used for formatting each of the ordered set’s elements (where recognized). Specify nil if you don’t want the elements formatted.

Return Value

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

Discussion

For a description of how locale is applied to each element in the receiving ordered set, see descriptionWithLocale:indent:.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

descriptionWithLocale:indent:

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

- (NSString *)descriptionWithLocale:(id)locale indent:(NSUInteger)level
Parameters
locale

An NSLocale object or an NSDictionary object that specifies options used for formatting each of the array’s elements (where recognized). Specify nil if you don’t want the elements formatted.

level

Specifies a level of indentation, to make the output more readable: the indentation is (4 spaces) * level.

Return Value

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

Discussion

The returned NSString object contains the string representations of each of the ordered set’s elements, in order, from first to last. To obtain the string representation of a given element, descriptionWithLocale:indent: proceeds as follows:

  • If the element is an NSString object, it is used as is.

  • If the element responds to descriptionWithLocale:indent:, that method is invoked to obtain the element’s string representation.

  • If the element responds to descriptionWithLocale:, that method is invoked to obtain the element’s string representation.

  • If none of the above conditions is met, the element’s string representation is obtained by invoking its description method

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

enumerateObjectsAtIndexes:options:usingBlock:

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

- (void)enumerateObjectsAtIndexes:(NSIndexSet *)indexSet options:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block
Parameters
indexSet

The indexes of the objects over which to enumerate.

opts

A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

block

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the ordered set.

idx

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YES within the block.

Discussion

By default, the enumeration starts with the first object and continues serially through the ordered set to the last element specified by indexSet. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

enumerateObjectsUsingBlock:

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

- (void)enumerateObjectsUsingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block
Parameters
block

The block to apply to elements in the ordered set.

The block takes three arguments:

idx

The element in the set.

idx

The index of the item in the set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

The block returns a Boolean value that indicates whether obj passed the test.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

enumerateObjectsWithOptions:usingBlock:

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

- (void)enumerateObjectsWithOptions:(NSEnumerationOptions)opts usingBlock:(void (^)(id obj, NSUInteger idx, BOOL *stop))block
Parameters
opts

A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

block

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the set.

idx

The index of the item in the set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

The block returns a Boolean value that indicates whether obj passed the test.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (NSOrderedSet *)filteredOrderedSetUsingPredicate:(NSPredicate *)predicate
Parameters
predicate

The predicate against which to evaluate the receiving ordered set’s elements.

Return Value

A new ordered set containing the objects in the receiving ordered set for which predicate returns true.

Discussion

For more details, see Predicate Programming Guide.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSPredicate.h

firstObject

Returns the first object in the ordered set.

- (id)firstObject
Return Value

The first object in the ordered set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

getObjects:range:

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

- (void)getObjects:(id [])objects range:(NSRange)range
Parameters
objects

A C array of objects of size at least the length of the range specified by aRange.

range

A range within the bounds of the array.

If the location plus the length of the range is greater than the count of the array, this method raises an NSRangeException.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (NSIndexSet *)indexesOfObjectsAtIndexes:(NSIndexSet *)indexSet options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate
Parameters
indexSet

The indexes of the objects over which to enumerate.

opts

A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

predicate

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the ordered set.

idx

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

The block returns a Boolean value that indicates whether obj passed the test.

Return Value

The index of the corresponding value in the ordered set that passes the test specified by predicate. If no objects in the ordered set pass the test, returns NSNotFound.

Discussion

By default, the enumeration starts with the first object and continues serially through the ordered set to the last object. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

indexesOfObjectsPassingTest:

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

- (NSIndexSet *)indexesOfObjectsPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate
Parameters
predicate

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the ordered set.

Term

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

Return Value

The index of the corresponding value in the ordered set that passes the test specified by predicate. If no objects in the ordered set pass the test, returns NSNotFound..

Discussion

If the block parameter is nil, this method raises an exception.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (NSIndexSet *)indexesOfObjectsWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate
Parameters
opts

A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

predicate

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the ordered set.

Term

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

Return Value

The index whose corresponding value in the ordered set passes the test specified by predicate and opts. If the opts bitmask specifies reverse order, then the last item that matches is returned. Otherwise, the index of the first matching object is returned. If no objects in the ordered set pass the test, returns NSNotFound.

Discussion

By default, the enumeration starts with the first object and continues serially through the ordered set to the last object. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

indexOfObject:

Returns the index of the specified object.

- (NSUInteger)indexOfObject:(id)object
Parameters
object

The object.

Return Value

The index whose corresponding ordered set value is equal to object. If none of the objects in the ordered set is equal to object, returns NSNotFound.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (NSUInteger)indexOfObject:(id)object inSortedRange:(NSRange)range options:(NSBinarySearchingOptions)opts usingComparator:(NSComparator)cmp
Parameters
object

An object for which to search in the ordered set.

If this value is nil, throws an NSInvalidArgumentException.

range

The range within the array to search for object.

If r exceeds the bounds of the ordered set (if the location plus length of the range is greater than the count of the ordered set), throws an NSRangeException.

opts

Options for the search. For possible values, see NSBinarySearchingOptions.

cmp

A comparator block used to compare the object obj with elements in the ordered set.

If this value is NULL, throws an NSInvalidArgumentException.

Return Value

If the NSBinarySearchingInsertionIndex option is not specified:

If the NSBinarySearchingInsertionIndex option is specified, returns the index at which you should insert obj in order to maintain a sorted array:

Discussion

The elements in the ordered set must have already been sorted using the comparator cmp. If the ordered set is not sorted, the result is undefined.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (NSUInteger)indexOfObjectAtIndexes:(NSIndexSet *)indexSet options:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate
Parameters
indexSet

The indexes of the objects over which to enumerate.

opts

A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

predicate

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the ordered set.

idx

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

The block returns a Boolean value that indicates whether obj passed the test.

Return Value

The index of the corresponding value in the ordered set passes the test specified by predicate. If no objects in the ordered set pass the test, returns NSNotFound.

Discussion

By default, the enumeration starts with the first object and continues serially through the ordered set to the last element specified by indexSet. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

indexOfObjectPassingTest:

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

- (NSUInteger)indexOfObjectPassingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate
Parameters
predicate

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the ordered set.

Term

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

Return Value

The index of the corresponding value in the ordered set that passes the test specified by predicate. If no objects in the ordered set pass the test, returns NSNotFound.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (NSUInteger)indexOfObjectWithOptions:(NSEnumerationOptions)opts passingTest:(BOOL (^)(id obj, NSUInteger idx, BOOL *stop))predicate
Parameters
opts

A bitmask that specifies the options for the enumeration (whether it should be performed concurrently and whether it should be performed in reverse order).

predicate

The block to apply to elements in the ordered set.

The block takes three arguments:

obj

The element in the array.

idx

The index of the element in the ordered set.

stop

A reference to a Boolean value. The block can set the value to YES to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YES within the block.

The block returns a Boolean value that indicates whether obj passed the test.

Return Value

The index whose corresponding value in the ordered set passes the test specified by predicate and opts. If no objects in the ordered set pass the test, returns NSNotFound.

Discussion

By default, the enumeration starts with the first object and continues serially through the ordered set to the last object. You can specify NSEnumerationConcurrent and/or NSEnumerationReverse as enumeration options to modify this behavior.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

init

Initializes a newly allocated ordered set.

- (instancetype)init
Return Value

An ordered set.

Discussion

This method is a designated initializer of NSOrderedSet.

Availability
  • Available in OS X v10.9 and later.
Declared In
NSOrderedSet.h

initWithArray:

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

- (instancetype)initWithArray:(NSArray *)array
Parameters
array

An array of objects to add to the new set.

If the same object appears more than once in array, it is represented only once in the returned ordered set.

Return Value

An initialized ordered set with the contents of array. The returned ordered set might be different than the original receiver.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithArray:copyItems:

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

- (instancetype)initWithArray:(NSArray *)array copyItems:(BOOL)flag
Parameters
array

An array of objects to add to the new set.

If the same object appears more than once in array, it is represented only once in the returned ordered set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

An initialized ordered set containing a uniqued collection of the objects contained in the array.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (instancetype)initWithArray:(NSArray *)array range:(NSRange)range copyItems:(BOOL)flag
Parameters
array

An array of objects to add to the new set.

If the same object appears more than once in array, it is represented only once in the returned ordered set.

range

The range of objects in array to add to the ordered set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

An initialized ordered set containing a uniqued collection of the objects contained in specified range of the the array.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithObject:

Initializes a new ordered set with the object.

- (instancetype)initWithObject:(id)object
Parameters
object

The object to add to the new ordered set

Return Value

A new ordered set that contains a single member, object.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithObjects:

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

- (instancetype)initWithObjects:(id)firstObj,, ...
Parameters
firstObj,

The first object to add to the new set.

...

A comma-separated list of objects, ending with nil, to add to the new ordered set.

If the same object appears more than once in the list, it is represented only once in the returned ordered set.

Return Value

An initialized ordered set containing the objects specified in the parameter list. The returned set might be different than the original receiver.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithObjects:count:

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

- (instancetype)initWithObjects:(const id [])objects count:(NSUInteger)cnt
Parameters
objects

A C array of objects to add to the new set.

If the same object appears more than once in objects, it is added only once to the returned ordered set.

cnt

The number of objects from objects to add to the new ordered set.

Return Value

An initialized ordered set containing cnt objects from the list of objects specified by objects. The returned set might be different than the original receiver.

This method is a designated initializer of NSOrderedSet.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithOrderedSet:

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

- (instancetype)initWithOrderedSet:(NSOrderedSet *)set
Parameters
set

A set.

Return Value

An initialized ordered set containing references to the objects in the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithOrderedSet:copyItems:

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

- (instancetype)initWithOrderedSet:(NSOrderedSet *)set copyItems:(BOOL)flag
Parameters
set

A set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

An initialized ordered set containing the objects in the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithOrderedSet:range:copyItems:

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

- (instancetype)initWithOrderedSet:(NSOrderedSet *)orderedSet range:(NSRange)range copyItems:(BOOL)flag
Parameters
orderedSet

An ordered set.

range

The range of objects in orderedSet to add to the ordered set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

An initialized ordered set containing the objects in the ordered set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithSet:

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

- (instancetype)initWithSet:(NSSet *)set
Parameters
set

The set.

Return Value

An initialized ordered set containing the objects in the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

initWithSet:copyItems:

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

- (instancetype)initWithSet:(NSSet *)set copyItems:(BOOL)flag
Parameters
set

The set.

flag

If YES the objects are copied to the ordered set; otherwise NO.

Return Value

An initialized ordered set containing the objects in the set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

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.

- (BOOL)intersectsOrderedSet:(NSOrderedSet *)other
Parameters
other

The other ordered set.

Return Value

YES if at least one object in the receiving ordered set is also present in other, otherwise NO.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

intersectsSet:

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

- (BOOL)intersectsSet:(NSSet *)set
Parameters
set

The set.

Return Value

YES if at least one object in the receiving ordered set is also present in other, otherwise NO.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

isEqualToOrderedSet:

Compares the receiving ordered set to another ordered set.

- (BOOL)isEqualToOrderedSet:(NSOrderedSet *)other
Parameters
other

The ordered set with which to compare the receiving ordered set.

Return Value

YES if the contents of other are equal to the contents of the receiving ordered set, otherwise NO.

Discussion

Two ordered sets have equal contents if they each have the same number of members, if each member of one ordered set is present in the other, and the members are in the same order.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

isSubsetOfOrderedSet:

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

- (BOOL)isSubsetOfOrderedSet:(NSOrderedSet *)other
Parameters
other

The ordered set with which to compare the receiving ordered set.

Return Value

YES if every object in the receiving set is also present in other, otherwise NO.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

isSubsetOfSet:

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

- (BOOL)isSubsetOfSet:(NSSet *)set
Parameters
set

The set with which to compare the receiving ordered set.

Return Value

YES if every object in the receiving ordered set is also present in set, otherwise NO.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

lastObject

Returns the last object in the ordered set.

- (id)lastObject
Return Value

The last object in the ordered set.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

objectAtIndex:

Returns the object at the specified index of the set.

- (id)objectAtIndex:(NSUInteger)index
Parameters
index

The object located at index.

Return Value

If index is beyond the end of the ordered set (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

objectAtIndexedSubscript:

Returns the object at the specified index of the set.

- (id)objectAtIndexedSubscript:(NSUInteger)index
Parameters
index

The object located at index.

Return Value

If index is beyond the end of the ordered set (that is, if index is greater than or equal to the value returned by count), an NSRangeException is raised.

Discussion

This method is the same as objectAtIndex:.

Availability
  • Available in OS X v10.8 and later.
Declared In
NSOrderedSet.h

objectEnumerator

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

- (NSEnumerator *)objectEnumerator
Return Value

An enumerator object that lets you access each object in the ordered set, in order, from the element at the lowest index upwards.

Special Considerations

When you use this method with mutable subclasses of NSOrderedSet, you must not modify the ordered set during enumeration.

It is more efficient to use the fast enumeration protocol (see NSFastEnumeration). Fast enumeration is available on OS X v10.5 and later and iOS 2.0 and later.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

objectsAtIndexes:

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

- (NSArray *)objectsAtIndexes:(NSIndexSet *)indexes
Parameters
indexes

The indexes.

Return Value

The returned objects are in the ascending order of their indexes in indexes, so that object in returned ordered set with higher index in indexes will follow the object with smaller index in indexes.

Discussion

Raises an NSRangeException if any location in indexes exceeds the bounds of the array, of if indexes is nil.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

removeObserver:forKeyPath:

Raises an exception.

- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
Parameters
observer

The object to remove as an observer.

keyPath

A key-path, relative to the set, for which observer is registered to receive KVO change notifications. This value must not be nil.

Discussion

NSOrderedSet objects are not observable, so this method raises an exception when invoked on an NSOrderedSet object. Instead of observing an ordered set, observe the to-many relationship for which the ordered set is the collection of related objects.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSKeyValueObserving.h

removeObserver:forKeyPath:context:

Raises an exception.

- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath context:(void *)context
Parameters
observer

The object to remove as an observer.

keyPath

A key-path, relative to the set, for which observer is registered to receive KVO change notifications. This value must not be nil.

context

The context passed to the notifications.

Discussion

NSOrderedSet objects are not observable, so this method raises an exception when invoked on an NSOrderedSet object. Instead of observing an ordered set, observe the to-many relationship for which the ordered set is the collection of related objects.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSKeyValueObserving.h

reversedOrderedSet

Returns an ordered set in the reverse order.

- (NSOrderedSet *)reversedOrderedSet
Return Value

Returns an ordered set in the reversed order of the receiver.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

reverseObjectEnumerator

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

- (NSEnumerator *)reverseObjectEnumerator
Return Value

An enumerator object that lets you access each object in the ordered set, in order, from the element at the highest index downwards.

Special Considerations

When you use this method with mutable subclasses of NSOrderedSet, you must not modify the ordered set during enumeration.

It is more efficient to use the fast enumeration protocol (see NSFastEnumeration). Fast enumeration is available on OS X v10.5 and later and iOS 2.0 and later.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

set

Returns a representation of the set containing the contents of the ordered set.

- (NSSet *)set
Return Value

A set containing the ordered set’s elements.

Discussion

This return a proxy object for the receiving ordered set, which acts like an immutable set.

While you cannot mutate the ordered set through this proxy, mutations to the original ordered set will be reflected in the proxy and it will appear to change spontaneously, since a copy of the ordered set is not being made.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

setValue:forKey:

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

- (void)setValue:(id)value forKey:(NSString *)key
Parameters
value

The object value.

key

The key to store the value.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSKeyValueCoding.h

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

- (NSArray *)sortedArrayUsingComparator:(NSComparator)cmptr
Parameters
cmptr

A comparator block.

Return Value

An array that lists the receiving ordered set’s elements in ascending order, as determined by the comparison method specified cmptr.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

sortedArrayUsingDescriptors:

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

- (NSArray *)sortedArrayUsingDescriptors:(NSArray *)sortDescriptors
Parameters
sortDescriptors

An array of NSSortDescriptor objects.

Return Value

An NSArray containing the ordered set’s elements sorted as specified by sortDescriptors.

Discussion

The first descriptor specifies the primary key path to be used in sorting the ordered set’s elements. Any subsequent descriptors are used to further refine sorting of objects with duplicate values. See NSSortDescriptor for additional information.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSSortDescriptor.h

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.

- (NSArray *)sortedArrayWithOptions:(NSSortOptions)opts usingComparator:(NSComparator)cmptr
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.

Return Value

An array that lists the receiving ordered set’s elements in ascending order, as determined by the comparison method specified cmptr.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSOrderedSet.h

valueForKey:

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

- (id)valueForKey:(NSString *)key
Parameters
key

The key to retrieve.

Return Value

The ordered set of the values for the retrieved key. The returned ordered set might not have the same number of members as the receiver.

Discussion

The returned ordered set will not contain any elements corresponding to instances of valueForKey: returning nil, nor will it contain duplicates.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSKeyValueCoding.h