iOS Developer Library

Developer

Foundation Framework Reference NSOrderedSet Class Reference

Options
Deployment Target:

On This Page
Language:

NSOrderedSet

Inherits From


Conforms To


Import Statement


Swift

import Foundation

Objective-C

@import Foundation;

Availability


Available in iOS 5.0 and later

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.

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

    Declaration

    Swift

    convenience init(array array: [AnyObject])

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(array array: [AnyObject], copyItems flag: Bool)

    Objective-C

    - (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 YEStrue the objects are copied to the ordered set; otherwise NOfalse.

    Return Value

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(array array: [AnyObject], range range: NSRange, copyItems flag: Bool)

    Objective-C

    - (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 YEStrue the objects are copied to the ordered set; otherwise NOfalse.

    Return Value

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Initializes a new ordered set with the object.

    Declaration

    Swift

    convenience init(object object: AnyObject)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    init(objects objects: UnsafePointer<AnyObject?>, count cnt: Int)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(orderedSet set: NSOrderedSet)

    Objective-C

    - (instancetype)initWithOrderedSet:(NSOrderedSet *)set

    Parameters

    set

    A set.

    Return Value

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(orderedSet set: NSOrderedSet, copyItems flag: Bool)

    Objective-C

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

    Parameters

    set

    A set.

    flag

    If YEStrue the objects are copied to the ordered set; otherwise NOfalse.

    Return Value

    An initialized ordered set containing the objects in the set.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(orderedSet orderedSet: NSOrderedSet, range range: NSRange, copyItems flag: Bool)

    Objective-C

    - (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 YEStrue the objects are copied to the ordered set; otherwise NOfalse.

    Return Value

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(set set: Set<NSObject>)

    Objective-C

    - (instancetype)initWithSet:(NSSet *)set

    Parameters

    set

    The set.

    Return Value

    An initialized ordered set containing the objects in the set.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    convenience init(set set: Set<NSObject>, copyItems flag: Bool)

    Objective-C

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

    Parameters

    set

    The set.

    flag

    If YEStrue the objects are copied to the ordered set; otherwise NOfalse.

    Return Value

    An initialized ordered set containing the objects in the set.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • init() - init Designated Initializer

    Initializes a newly allocated ordered set.

    Declaration

    Swift

    init()

    Objective-C

    - (instancetype)init

    Return Value

    An ordered set.

    Discussion

    This method is a designated initializer of NSOrderedSet.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 7.0 and later

  • count count Property

    The number of members in the set. (read-only)

    Declaration

    Swift

    var count: Int { get }

    Objective-C

    @property(readonly) NSUInteger count

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func containsObject(_ object: AnyObject) -> Bool

    Objective-C

    - (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 NOfalse.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func enumerateObjectsAtIndexes(_ indexSet: NSIndexSet, options opts: NSEnumerationOptions, usingBlock block: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (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 YEStrue to stop further processing of the array. The stop argument is an out-only argument. You should only ever set this Boolean to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func enumerateObjectsUsingBlock(_ block: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue within the block.

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func enumerateObjectsWithOptions(_ opts: NSEnumerationOptions, usingBlock block: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Void)

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue within the block.

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • The first object in the ordered set. (read-only)

    Declaration

    Swift

    var firstObject: AnyObject? { get }

    Objective-C

    @property(nonatomic, readonly) id firstObject

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

    See Also

    – lastObject

  • The last object in the ordered set. (read-only)

    Declaration

    Swift

    var lastObject: AnyObject? { get }

    Objective-C

    @property(nonatomic, readonly) id lastObject

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

    See Also

    – firstObject

  • Returns the object at the specified index of the set.

    Declaration

    Swift

    func objectAtIndex(_ index: Int) -> AnyObject

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Returns the object at the specified index of the set.

    Declaration

    Objective-C

    - (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:.

    Import Statement

    Objective-C

    @import Foundation;

    Availability

    Available in iOS 6.0 and later

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

    Declaration

    Swift

    func objectsAtIndexes(_ indexes: NSIndexSet) -> [AnyObject]

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Returns the index of the specified object.

    Declaration

    Swift

    func indexOfObject(_ object: AnyObject) -> Int

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func indexOfObject(_ object: AnyObject, inSortedRange range: NSRange, options opts: NSBinarySearchingOptions, usingComparator cmp: NSComparator) -> Int

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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.

    Declaration

    Swift

    func indexOfObjectAtIndexes(_ indexSet: NSIndexSet, options opts: NSEnumerationOptions, passingTest predicate: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func indexOfObjectPassingTest(_ predicate: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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.

    Declaration

    Swift

    func indexOfObjectWithOptions(_ opts: NSEnumerationOptions, passingTest predicate: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> Int

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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.

    Declaration

    Swift

    func indexesOfObjectsAtIndexes(_ indexSet: NSIndexSet, options opts: NSEnumerationOptions, passingTest predicate: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func indexesOfObjectsPassingTest(_ predicate: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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.

    Declaration

    Swift

    func indexesOfObjectsWithOptions(_ opts: NSEnumerationOptions, passingTest predicate: (AnyObject!, Int, UnsafeMutablePointer<ObjCBool>) -> Bool) -> NSIndexSet

    Objective-C

    - (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 YEStrue to stop further processing of the set. The stop argument is an out-only argument. You should only ever set this value to YEStrue 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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func objectEnumerator() -> NSEnumerator

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func reverseObjectEnumerator() -> NSEnumerator

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • An ordered set in the reverse order. (read-only)

    Declaration

    Swift

    @NSCopying var reversedOrderedSet: NSOrderedSet { get }

    Objective-C

    @property(readonly, copy) NSOrderedSet *reversedOrderedSet

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func getObjects(_ objects: AutoreleasingUnsafeMutablePointer<AnyObject?>, range range: NSRange)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func setValue(_ value: AnyObject?, forKey key: String)

    Objective-C

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

    Parameters

    value

    The object value.

    key

    The key to store the value.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func valueForKey(_ key: String) -> AnyObject

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Raises an exception.

    Declaration

    Swift

    func addObserver(_ observer: NSObject, forKeyPath keyPath: String, options options: NSKeyValueObservingOptions, context context: UnsafeMutablePointer<Void>)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Raises an exception.

    Declaration

    Swift

    func removeObserver(_ observer: NSObject, forKeyPath keyPath: String)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Raises an exception.

    Declaration

    Swift

    func removeObserver(_ observer: NSObject, forKeyPath keyPath: String, context context: UnsafeMutablePointer<Void>)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • Compares the receiving ordered set to another ordered set.

    Declaration

    Swift

    func isEqualToOrderedSet(_ other: NSOrderedSet) -> Bool

    Objective-C

    - (BOOL)isEqualToOrderedSet:(NSOrderedSet *)other

    Parameters

    other

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

    Return Value

    YEStrue if the contents of other are equal to the contents of the receiving ordered set, otherwise NOfalse.

    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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func intersectsOrderedSet(_ other: NSOrderedSet) -> Bool

    Objective-C

    - (BOOL)intersectsOrderedSet:(NSOrderedSet *)other

    Parameters

    other

    The other ordered set.

    Return Value

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func intersectsSet(_ set: Set<NSObject>) -> Bool

    Objective-C

    - (BOOL)intersectsSet:(NSSet *)set

    Parameters

    set

    The set.

    Return Value

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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func isSubsetOfOrderedSet(_ other: NSOrderedSet) -> Bool

    Objective-C

    - (BOOL)isSubsetOfOrderedSet:(NSOrderedSet *)other

    Parameters

    other

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

    Return Value

    YEStrue if every object in the receiving set is also present in other, otherwise NOfalse.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func isSubsetOfSet(_ set: Set<NSObject>) -> Bool

    Objective-C

    - (BOOL)isSubsetOfSet:(NSSet *)set

    Parameters

    set

    The set with which to compare the receiving ordered set.

    Return Value

    YEStrue if every object in the receiving ordered set is also present in set, otherwise NOfalse.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func sortedArrayUsingDescriptors(_ sortDescriptors: [AnyObject]) -> [AnyObject]

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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

    Declaration

    Swift

    func sortedArrayUsingComparator(_ cmptr: NSComparator) -> [AnyObject]

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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.

    Declaration

    Swift

    func sortedArrayWithOptions(_ opts: NSSortOptions, usingComparator cmptr: NSComparator) -> [AnyObject]

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • 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.

    Declaration

    Swift

    func filteredOrderedSetUsingPredicate(_ predicate: NSPredicate) -> NSOrderedSet

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • A string that represents the contents of the ordered set, formatted as a property list. (read-only)

    Declaration

    Swift

    var description: String { get }

    Objective-C

    @property(readonly, copy) NSString *description

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func descriptionWithLocale(_ locale: AnyObject?) -> String?

    Objective-C

    - (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:.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

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

    Declaration

    Swift

    func descriptionWithLocale(_ locale: AnyObject?, indent level: Int) -> String

    Objective-C

    - (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

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • array array Property

    A representation of the ordered set as an array. (read-only)

    Declaration

    Swift

    var array: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *array

    Discussion

    This returns 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, because a copy of the ordered set is not being made.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later

  • set set Property

    A representation of the set containing the contents of the ordered set. (read-only)

    Declaration

    Swift

    var set: Set<NSObject> { get }

    Objective-C

    @property(readonly, copy) NSSet *set

    Discussion

    This returns 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, because a copy of the ordered set is not being made.

    Import Statement

    Objective-C

    @import Foundation;

    Swift

    import Foundation

    Availability

    Available in iOS 5.0 and later