目前我有一个核心数据应用程序,它有一个视图控制器,需要对UITableView进行特定的排序。实体可以包含event_name
和assigned_time
以及其他属性。基本思路是如果事件被分配到更近的时间,那么该事件将首先显示在tableview中。
我想知道的是assigned_time
按event_name
分组我的信息的最佳方式是什么?我已尝试将NSSortDescriptor
用于assigned_time
部分但我最后按名称排序,并且没有事先在事件中排在第一位。
基本上我想要实现类似于电子邮件线程如何工作的东西,其中具有更新{{}}}的实体将推送列表中的部分,因此部分排序取决于时间
我的NSFetchRequest代码如下:
assigned_time
答案 0 :(得分:0)
试试这个:
var request : NSFetchRequest<NSFetchRequestResult>!
request.sortDescriptors = [NSSortDescriptor(key: "event_name", ascending: true), NSSortDescriptor(key: "assigned_time", ascending: true)]
request.propertiesToGroupBy = ["event_name"]