Mac Developer Library

Developer

Foundation Framework Reference NSOrderedSet Class Reference

Options
Deployment Target:

On This Page
Language:

NSOrderedSet

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

Inheritance


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.7 and later.
  • 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 and later.

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

    Declaration

    Swift

    convenience init(set set: NSSet)

    Objective-C

    - (instancetype)initWithSet:(NSSet *)set

    Parameters

    set

    The set.

    Return Value

    An initialized ordered set containing the objects in the set.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.7 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: NSSet, 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.9 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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: NSSet) -> 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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: NSSet) -> 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 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

    import Foundation

    Availability

    Available in OS X v10.7 and later.

  • set set Property

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

    Declaration

    Swift

    @NSCopying var set: NSSet { 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

    import Foundation

    Availability

    Available in OS X v10.7 and later.