core dataģģ stringķķģ columnģ ģ«ģģģ¼ė” ģ ė ¬ķė ė°©ė²
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true, selector: "localizedStandardCompare:" )]
seen from Italy

seen from T1
seen from Türkiye
seen from Saudi Arabia

seen from United States

seen from United States

seen from United States

seen from Australia

seen from United States

seen from China

seen from India
seen from Malaysia

seen from United States

seen from Australia
seen from Ukraine
seen from China

seen from United States

seen from United States
seen from United States

seen from Italy
core dataģģ stringķķģ columnģ ģ«ģģģ¼ė” ģ ė ¬ķė ė°©ė²
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "id", ascending: true, selector: "localizedStandardCompare:" )]

Anya is live and ready to show you everything. Watch her strip, dance, and perform exclusive shows just for you. Interact in real-time and make your fantasies come true.
Free to watch ⢠No registration required ⢠HD streaming
Sorting: it's the mainstay of Computer Science 101 exams and whiteboarding interview questions. But when was the last time you actually needed to know how to implement Quicksort yourself?
original source :Ā https://nshipster.com/nssortdescriptor/
core dataģģ sortģ źø°ė³øģ ģģ ģė¤.
my review point is 9/10
Sorting: itās the mainstay of Computer Science 101 exams and whiteboarding interview questions. But when was the last time you actually needed to know how to implement Quicksort yourself?
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.
NSSortDescriptor objects are constructed with the following parameters:
key: for a given collection, the key for the corresponding value to be sorted on for each object in the collection.
ascending: a boolean specifying whether the collection should be sorted in ascending (YES) or descending (NO) order.
There is an optional third parameter that relates to how the sorted values are compared to one another. By default, this is a simple equality check, but this behavior can be changed by passing either a selector (SEL) or comparator (NSComparator).
Any time youāre sorting user-facing strings, be sure to pass the selector localizedStandardCompare:, which will sort according to the language rules of the current locale (locales may differ on ordering of case, diacritics, and so forth).
Collection classes like NSArray and NSSet have methods to return sorted arrays of the objects that take an array of sortDescriptors. Sort descriptors are applied in order, so that if two elements happen to be tied for a particular sorting criteria, the tie is broken by any subsequent descriptors.
To put that into more practical terms, consider a Person class with properties for firstName & lastName of type NSString *, and age, which is an NSUInteger.
Swift
class Person: NSObject { Ā Ā let firstName: String Ā Ā let lastName: String Ā Ā let age: Int Ā Ā init(firstName: String, lastName: String, age: Int) { Ā Ā Ā Ā self.firstName = firstName Ā Ā Ā Ā self.lastName = lastName Ā Ā Ā Ā self.age = age Ā Ā } Ā Ā override var description: String { Ā Ā Ā Ā return "\(firstName) \(lastName)" Ā Ā } }
Given the following dataset:
Here are some of the different ways they can be sorted by combinations of NSSortDescriptor:
Swift
let alice = Person(firstName: "Alice", lastName: "Smith", age: 24) let bob = Person(firstName: "Bob", lastName: "Jones", age: 27) let charlie = Person(firstName: "Charlie", lastName: "Smith", age: 33) let quentin = Person(firstName: "Quentin", lastName: "Alberts", age: 31) let people = [alice, bob, charlie, quentin] let firstNameSortDescriptor = NSSortDescriptor(key: "firstName", ascending: true, selector: "localizedStandardCompare:") let lastNameSortDescriptor = NSSortDescriptor(key: "lastName", ascending: true, selector: "localizedStandardCompare:") let ageSortDescriptor = NSSortDescriptor(key: "age", ascending: false) let sortedByAge = (people as NSArray).sortedArrayUsingDescriptors([ageSortDescriptor]) // "Charlie Smith", "Quentin Alberts", "Bob Jones", "Alice Smith" let sortedByFirstName = (people as NSArray).sortedArrayUsingDescriptors([firstNameSortDescriptor]) // "Alice Smith", "Bob Jones", "Charlie Smith", "Quentin Alberts" let sortedByLastNameFirstName = (people as NSArray).sortedArrayUsingDescriptors([lastNameSortDescriptor, firstNameSortDescriptor]) // "Quentin Alberts", "Bob Jones", "Alice Smith", "Charlie Smith"
NSSortDescriptor can be found throughout Foundation and other system frameworks, playing an especially prominent role in Core Data. Anytime your own classes need to define sort ordering, follow the convention of specifying a sortDescriptors parameter as appropriate.
Because, in reality, sorting should be thought of in terms of business logic, not mathematical formulas and map-reduce functions. In this respect, NSSortDescriptor is a slam dunk, and will have you pining for it anytime you venture out of Objective-C and Cocoa.
nsmutablehipster
Questions? Corrections? Issues and pull requests are always welcome ā NSHipster is made better by readers like you.
This article uses Swift version 1.1. Find status information for all articles on the status page.