简体   繁体   中英

How to use predicate to get ordered list of Core Data NSSet relationship?

I have an instance of the Department entity, which in turn has a relationship to the Employee entity via the 'employees' to-many relationship.

How would I construct my NSPredicate to return an array of employees within the specific department, in employeeNumber order, from this Department instance?

A predicate's purpose is to filter items, not to sort them. Use your fetch request's sortDescriptors property to determine how the results are sorted.

Alternatively, if you're accessing the relationship via the object's properties, use the NSSet method sortedArrayUsingDescriptors: to create a sorted array from the set of objects.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM