默认情况下,核心数据提取(NSFetchRequest)是否按任何特定方式排序? [英] Are Core Data fetches (NSFetchRequest) sorted in any specific fashion by default?

查看:256
本文介绍了默认情况下,核心数据提取(NSFetchRequest)是否按任何特定方式排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本问题。假设你有一个NSFetchRequest,你想在一个NSManagedObjectContext上执行。如果获取请求没有明确设置任何排序描述符,对象将是每次都是随机的,还是将按照它们最初添加到受管对象上下文的顺序排列到数组中?我在文档中的任何位置找不到此答案。

I have a basic question. Say you have a NSFetchRequest which you want to perform on a NSManagedObjectContext. If the fetch request doesn't have any sort descriptors set to it explicitly, will the objects be random every time, or are they going to be spit out into an array in the order they were added to the Managed Object Context initially? I can't find this answer anywhere in the documentation.

推荐答案

不,他们不能保证是有序的。你可能会看到一致的顺序取决于你使用什么类型的数据存储(我从来没有尝试过),但它不是你应该依赖任何方式。

No, they're not guaranteed to be ordered. You might happen to see consistent ordering depending on what type of data store you use (I've never tried), but it's not something you should depend on in any way.

很容易按照创建日期排序。只需在您的实体中添加日期属性,将其初始化为 awakeFromInsert 中的当前日期,并在您的抓取中指定排序描述符。

It's easy to order by creation date though. Just add a date attribute to your entity, initialize it to the current date in awakeFromInsert, and specify that sort descriptor in your fetch.

这篇关于默认情况下,核心数据提取(NSFetchRequest)是否按任何特定方式排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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