My data model is as such:
User (Entity)
- valueOne (NSNumber Attribute)
- valueTwo (NSNumber Attribute)
I am using an NSFetchedResultsController
to fetch User
entities from Core Data to display in my UITableView
. I am having trouble sorting the results of the fetch request. I need to sort by valueOne (divided by) valueTwo
. I have tried passing both @"self"
and nil
for the Key value of sortDescriptorWithKey:ascending:selector:
to obtain the User
object. I would then sort by the User.valueOne / User.valueTwo
values in my custom selector, but neither @"self"
or nil
seem to work, as I get errors for both. The documentation doesn't seem to contain anything about how to pass the parent object for the key to sort by.
How would I go about creating an NSSortDescriptor
which sorts by valueOne / valueTwo
?
That is not possible. The sort descriptor for a Core Data fetch request can only sort according to (persistent) attributes of the entities. Transient attributes or custom (Objective-C based) comparator methods cannot be used.