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+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
You construct instances of
NSSort by specifying the key path of the property to be compared 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
localized. Sorting raises an exception if the objects to be sorted do not respond to the sort descriptor’s comparison selector.
You can use sort descriptors to, for example: