Suppose I have Person
entity with properties: id, name, age
:
And I have following records:
101, Katherine, 23 102, Madelaine, 23 103, Katherine, 27 104, Vicky, 18 105, Kirsten, 45 106, Vicky, 12
And I need all records sorted by age, without duplicating name.
The output should be:
105, Kirsten, 45 103, Katherine, 27 102, Madelaine, 23 104, Vicky, 18
This is how I create NSFRC:
let context = NSManagedObjectContext.mr_default()
let fetchRequest = NSFetchRequest<Person>(entityName: "Person")
let ageDescriptor = NSSortDescriptor(key: "age", ascending: false)
fetchRequest.sortDescriptors = [ageDescriptor]
fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: context, sectionNameKeyPath: nil, cacheName: nil)
fetchedResultsController.delegate = self
How to apply rule to fetch all persons and only one (oldest) person with the same name?