核心数据子顺序集 [英] Core Data Child Ordered Set

查看:76
本文介绍了核心数据子顺序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在核心数据中有两个具有父子关系的实体(订单和购物车)。生成的父类具有访问子记录的属性。

I have two entities (Order and Cart) in core data with a parent child relationship. The generated parent class has a property to access the child records.

@interface Order : NSManagedObject

@property(nonatomic, retain) NSOrderedSet *carts;

@end

说,购物车的字段为 x,是是否有可能告诉核心数据框架将上面的 carts 集合始终按x排序?

Say, Cart has a field 'x', is it possible to tell core data framework to keep the carts collection above always ordered by x?

推荐答案

不带有 NSOrderedSet 。如果您对孩子有逻辑上的排序,那么您完全不必理会 NSOrderedSet ,而不必理会它们。更改之后,您可以使用 NSSortDescriptor 将子级排序为 NSArray

Not with an NSOrderedSet. If you have a logical sort for your children then you should not bother with a NSOrderedSet at all and just leave them as unordered. After that change you can use a NSSortDescriptor to sort the children into an NSArray.

NSOrderedSet 相比,这将为您带来更好的性能,并让您按 x 。

That will yield better performance for you compared to a NSOrderedSet and will let you sort by x.

有序关系非常昂贵,除非有绝对必要,否则应避免。

Ordered relationships are very expensive and should be avoided unless there is an absolute necessity.

这篇关于核心数据子顺序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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