An immutable description of how to order a collection of objects based on a property common to all the objects.
- iOS 2.0+
- macOS 10.3+
- tvOS 9.0+
- watchOS 2.0+
You construct an instance of
NSSort by specifying the key path of the property to be compared, the order of the sort (ascending or descending), and (optionally) a selector to use to perform the comparison. The three-argument constructor allows you to specify other comparison selectors such as
localized. Sorting raises an exception if the objects to be sorted do not respond to the sort descriptor’s comparison selector.
There are a number of situations in which you can use sort descriptors, for example:
To sort an array (an instance of
To directly compare two objects (see
To specify how the elements in a table view should be arranged (see
To specify how the elements managed by an array controller should be arranged (see
If you are using Core Data, to specify the ordering of objects returned from a fetch request (see