NSSortDescriptor
When making apps, sorting is just something you can assume to be fast, and utility is a function of convenience and clarity of intention. And when it comes to that, you’d be hard-pressed to find a better implementation than Foundation’s NSSortDescriptor.
→ nshipster.com/nssortdescriptor/
NSSortDescriptor is a Foundation class used to sort collections. It is created with a key (property to sort on), ascending (true for ascending order), and optionally a selector or comparator for comparisons.
For user-facing strings, use localizedStandardCompare: to respect locale rules. Collections like NSArray and NSSet have sortedArrayUsingDescriptors:, which takes an array of descriptors applied in sequence for tie-breaking.
Example: Sorting people by last name then first name uses two descriptors.
NSSortDescriptor appears in Core Data and other frameworks. Include sortDescriptors parameters in your APIs when sorting is needed. It focuses on business logic over algorithms, making it convenient and clear.
Category:
Tags:
Year: