user3654291
user3654291

Reputation: 1

Creating NSSortDescriptor

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

Answers (1)

cweinberger
cweinberger

Reputation: 3588

You can use the @count collection operator. See the documentation

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"jobs.@count" ascending:NO]

Upvotes: 1

Related Questions