简体   繁体   English

如何使用谓词获取Core Data NSSet关系的有序列表?

[英]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. 我有一个Department实体的实例,该实体又通过“雇员”对多关系与Employee实体有关系。

How would I construct my NSPredicate to return an array of employees within the specific department, in employeeNumber order, from this Department instance? 我将如何构造NSPredicate以从此Department实例以employeeNumber顺序返回特定部门内的一组雇员?

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. 使用获取请求的sortDescriptors属性来确定结果的排序方式。

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. 另外,如果要通过对象的属性访问关系,请使用NSSet方法sortedArrayUsingDescriptors:从对象集中创建一个排序数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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