---
title: NSSortDescriptor
framework: foundation
role: symbol
role_heading: Class
path: foundation/nssortdescriptor
---

# NSSortDescriptor

An immutable description of how to order a collection of objects according to a property common to all the objects.

## Declaration

```swift
class NSSortDescriptor
```

## Overview

Overview You construct instances of NSSortDescriptor by specifying the key path of the property to compare and the order of the sort (ascending or descending). Optionally, you can also specify a selector to use to perform the comparison, which allows you to specify other comparison selectors, such as localizedStandardCompare(_:) and localizedCaseInsensitiveCompare(_:). Sorting raises an exception if the objects don’t respond to the sort descriptor’s comparison selector. You can use sort descriptors for the following: Sorting an array (an instance of NSArray or NSMutableArray — see sortedArray(using:) and sort(using:)) Comparing two objects directly (see compare(_:to:)) Specifying the order of objects that return from a Core Data fetch request (see sortDescriptors)

## Topics

### Creating a Sort Descriptor

- [init(key:ascending:)](foundation/nssortdescriptor/init(key:ascending:).md)
- [init(key:ascending:selector:)](foundation/nssortdescriptor/init(key:ascending:selector:).md)
- [init(keyPath:ascending:)](foundation/nssortdescriptor/init(keypath:ascending:).md)
- [init(key:ascending:comparator:)](foundation/nssortdescriptor/init(key:ascending:comparator:).md)
- [init(keyPath:ascending:comparator:)](foundation/nssortdescriptor/init(keypath:ascending:comparator:).md)
- [init(coder:)](foundation/nssortdescriptor/init(coder:).md)
- [init(_:)](foundation/nssortdescriptor/init(_:)-7qf91.md)

### Getting Information About a Sort Descriptor

- [ascending](foundation/nssortdescriptor/ascending.md)
- [key](foundation/nssortdescriptor/key.md)
- [keyPath](foundation/nssortdescriptor/keypath.md)
- [selector](foundation/nssortdescriptor/selector.md)
- [comparator](foundation/nssortdescriptor/comparator.md)

### Using Sort Descriptors

- [compare(_:to:)](foundation/nssortdescriptor/compare(_:to:).md)
- [reversedSortDescriptor](foundation/nssortdescriptor/reversedsortdescriptor.md)
- [allowEvaluation()](foundation/nssortdescriptor/allowevaluation().md)

### Initializers

- [init(_:)](foundation/nssortdescriptor/init(_:)-527yl.md)

## Relationships

### Inherits From

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

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCoding](foundation/nscoding.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)
- [NSSecureCoding](foundation/nssecurecoding.md)

## See Also

### Sorting

- [ComparisonResult](foundation/comparisonresult.md)
- [SortDescriptor](foundation/sortdescriptor.md)
- [SortComparator](foundation/sortcomparator.md)
- [ComparableComparator](foundation/comparablecomparator.md)
- [KeyPathComparator](foundation/keypathcomparator.md)
- [SortOrder](foundation/sortorder.md)
