没有排序描述符的NSFetchRequest [英] NSFetchRequest without sort descriptors

查看:233
本文介绍了没有排序描述符的NSFetchRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们不能在不提供NSSortDescriptor的情况下使用NSFetchRequest。我想要做的就是获取结果并按照创建顺序显示它们。有内置的方法吗?或者我是否必须创建一个新的自动增量字段? (在我看来,这与CoreData所代表的一切相悖)。

We cannot use NSFetchRequest without providing NSSortDescriptor(s). All i want to do is fetch the results and show them in the order in which they were created. Is there a built-in way to do that?, or will i have to create a new "auto-increment" field? (which goes against everything CoreData stands for, in my opinion).

推荐答案

核心数据不保证订单的任何内容。您不必进行自动增量字段;但是,您可以创建适当的属性。由于您显然关心创建日期,因此应将dateCreated属性添加到数据对象中。然后,按此排序。

Core Data does not guarantee anything about order. You don't have to make an "auto-increment" field; however, you can make an appropriate attribute. Since you obviously care about the date something was created, you should add a dateCreated attribute to your data object. Then, sort by that.

您可以在托管对象的 didAwakeFromInsert 方法中轻松设置它。

You can easily set that in the managed object's didAwakeFromInsert method.

这篇关于没有排序描述符的NSFetchRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆