NSSortDescriptor
An immutable description of how to order a collection of objects according to a property common to all the objects.
Declaration
class NSSortDescriptorOverview
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:)init(key:ascending:selector:)init(keyPath:ascending:)init(key:ascending:comparator:)init(keyPath:ascending:comparator:)init(coder:)init(_:)