NSSortDescriptor
NSSortDescriptor is a foundation class used to describe how to sort a collection of objects. It encapsulates a single sorting criterion and can be combined with other descriptors to perform multi-level sorting. The descriptor is immutable and commonly applied to arrays via sorting methods that accept a list of sort descriptors.
Key properties and initializers
- key: the key path used to extract the value from each element, typically a property name or
- ascending: a boolean indicating whether the sort is in ascending or descending order.
- selector: an optional Objective-C selector that specifies how to compare values, allowing custom comparison logic.
- comparator: an optional block or closure that directly compares two values and returns a comparison result.
Sort descriptors are created with a key and an order, and optionally a comparator or selector. They
NSSortDescriptor supports sorting by values retrieved via KVC, and can use a default comparison method if no
Sort descriptors can be combined to form complex sorting rules, and are frequently used with NSArray