Reputation: 1
I'm trying to do a fetch on an entity for "Contractor". Contractor has a one-to-many relationship with another entity called "Job". So a contractor can have many jobs.
How would I create a NSSortDescriptor so my fetch is sorted by number of jobs the contractor has -- from greatest to least?
Thank you
Upvotes: 0
Views: 72
Reputation: 3588
You can use the @count
collection operator. See the documentation
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"jobs.@count" ascending:NO]
Upvotes: 1