---
title: NSOrderedSet
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsorderedset
---

# NSOrderedSet

A static, ordered collection of unique objects.

## Declaration

```swift
class NSOrderedSet
```

## Overview

Overview NSOrderedSet declares the programmatic interface for static sets of distinct objects. You establish a static set’s entries when it’s created, and thereafter the entries can’t be modified. NSMutableOrderedSet, on the other hand, declares a programmatic interface for dynamic sets of distinct objects. A dynamic—or mutable—set allows the addition and deletion of entries at any time, automatically allocating memory as needed. You can use ordered sets as an alternative to arrays when the order of elements is important and performance in testing whether an object is contained in the set is a consideration—testing for membership of an array is slower than testing for membership of a set.

## Topics

### Creating an Ordered Set

- [init(objects:count:)](foundation/nsorderedset/init(objects:count:)-3ny0m.md)

### Initializing an Ordered Set

- [init(array:)](foundation/nsorderedset/init(array:).md)
- [init(array:copyItems:)](foundation/nsorderedset/init(array:copyitems:).md)
- [init(array:range:copyItems:)](foundation/nsorderedset/init(array:range:copyitems:).md)
- [init(object:)](foundation/nsorderedset/init(object:).md)
- [init(objects:count:)](foundation/nsorderedset/init(objects:count:)-2ai32.md)
- [init(orderedSet:)](foundation/nsorderedset/init(orderedset:).md)
- [init(orderedSet:copyItems:)](foundation/nsorderedset/init(orderedset:copyitems:).md)
- [init(orderedSet:range:copyItems:)](foundation/nsorderedset/init(orderedset:range:copyitems:).md)
- [init(set:)](foundation/nsorderedset/init(set:).md)
- [init(set:copyItems:)](foundation/nsorderedset/init(set:copyitems:).md)
- [init()](foundation/nsorderedset/init().md)

### Counting Entries

- [count](foundation/nsorderedset/count.md)

### Accessing Set Members

- [contains(_:)](foundation/nsorderedset/contains(_:).md)
- [enumerateObjects(at:options:using:)](foundation/nsorderedset/enumerateobjects(at:options:using:).md)
- [enumerateObjects(_:)](foundation/nsorderedset/enumerateobjects(_:).md)
- [enumerateObjects(options:using:)](foundation/nsorderedset/enumerateobjects(options:using:).md)
- [firstObject](foundation/nsorderedset/firstobject.md)
- [lastObject](foundation/nsorderedset/lastobject.md)
- [object(at:)](foundation/nsorderedset/object(at:).md)
- [subscript(_:)](foundation/nsorderedset/subscript(_:).md)
- [objects(at:)](foundation/nsorderedset/objects(at:).md)
- [index(of:)](foundation/nsorderedset/index(of:).md)
- [index(of:inSortedRange:options:usingComparator:)](foundation/nsorderedset/index(of:insortedrange:options:usingcomparator:).md)
- [index(ofObjectAt:options:passingTest:)](foundation/nsorderedset/index(ofobjectat:options:passingtest:).md)
- [index(ofObjectPassingTest:)](foundation/nsorderedset/index(ofobjectpassingtest:).md)
- [index(_:ofObjectPassingTest:)](foundation/nsorderedset/index(_:ofobjectpassingtest:).md)
- [indexes(ofObjectsAt:options:passingTest:)](foundation/nsorderedset/indexes(ofobjectsat:options:passingtest:).md)
- [indexes(ofObjectsPassingTest:)](foundation/nsorderedset/indexes(ofobjectspassingtest:).md)
- [indexes(options:ofObjectsPassingTest:)](foundation/nsorderedset/indexes(options:ofobjectspassingtest:).md)
- [objectEnumerator()](foundation/nsorderedset/objectenumerator().md)
- [reverseObjectEnumerator()](foundation/nsorderedset/reverseobjectenumerator().md)
- [reversed](foundation/nsorderedset/reversed.md)

### Key-Value Coding Support

- [setValue(_:forKey:)](foundation/nsorderedset/setvalue(_:forkey:).md)
- [value(forKey:)](foundation/nsorderedset/value(forkey:).md)

### Key-Value Observing Support

- [addObserver(_:forKeyPath:options:context:)](foundation/nsorderedset/addobserver(_:forkeypath:options:context:).md)
- [removeObserver(_:forKeyPath:)](foundation/nsorderedset/removeobserver(_:forkeypath:).md)
- [removeObserver(_:forKeyPath:context:)](foundation/nsorderedset/removeobserver(_:forkeypath:context:).md)

### Comparing Sets

- [isEqual(to:)](foundation/nsorderedset/isequal(to:).md)
- [intersects(_:)](foundation/nsorderedset/intersects(_:).md)
- [intersectsSet(_:)](foundation/nsorderedset/intersectsset(_:).md)
- [isSubset(of:)](foundation/nsorderedset/issubset(of:)-7brc.md)
- [isSubset(of:)](foundation/nsorderedset/issubset(of:)-8zx9x.md)

### Creating a Sorted Array

- [sortedArray(using:)](foundation/nsorderedset/sortedarray(using:).md)
- [sortedArray(comparator:)](foundation/nsorderedset/sortedarray(comparator:).md)
- [sortedArray(options:usingComparator:)](foundation/nsorderedset/sortedarray(options:usingcomparator:).md)

### Filtering Ordered Sets

- [filtered(using:)](foundation/nsorderedset/filtered(using:).md)

### Describing a Set

- [description](foundation/nsorderedset/description.md)
- [description(withLocale:)](foundation/nsorderedset/description(withlocale:).md)
- [description(withLocale:indent:)](foundation/nsorderedset/description(withlocale:indent:).md)

### Converting Other Collections

- [array](foundation/nsorderedset/array.md)
- [set](foundation/nsorderedset/set.md)

### Comparing with Another Set

- [NSOrderedCollectionDifference](foundation/nsorderedcollectiondifference.md)
- [NSOrderedCollectionDifferenceCalculationOptions](foundation/nsorderedcollectiondifferencecalculationoptions.md)

### Initializers

- [init(coder:)](foundation/nsorderedset/init(coder:).md)
- [init(objects:)](foundation/nsorderedset/init(objects:).md)

### Default Implementations

- [ExpressibleByArrayLiteral Implementations](foundation/nsorderedset/expressiblebyarrayliteral-implementations.md)
- [Sequence Implementations](foundation/nsorderedset/sequence-implementations.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Inherited By

- [NSMutableOrderedSet](foundation/nsmutableorderedset.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [Copyable](swift/copyable.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Escapable](swift/escapable.md)
- [ExpressibleByArrayLiteral](swift/expressiblebyarrayliteral.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSFastEnumeration](foundation/nsfastenumeration.md)
- [NSMutableCopying](foundation/nsmutablecopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)
- [Sequence](swift/sequence.md)

## See Also

### Specialized Sets

- [NSCountedSet](foundation/nscountedset.md)
- [NSMutableOrderedSet](foundation/nsmutableorderedset.md)
