核心数据:根据实体类型对抽象实体的结果进行排序
是否可以根据实体类型对 Core Data 的结果进行排序,但是:
- 无需添加名为
entityType
之类的虚假属性,并且 - 不会通过使用 KVO/KVC 技巧(例如引入)对性能产生不利影响
-(NSString*)typeOfEntity
或类似的?
我目前有:
TradeDocument
作为抽象实体,QuoteTradeDocument
和InvoiceTradeDocument
作为基于它的实体。
我想显示实体类型和/或允许 NSTableView 基于此进行排序。
我在 OS X 上使用 Cocoa Bindings。
注意:我明确地试图避免每个对象出错。
Is it possible to sort results from Core Data based on the entity type, but:
- without resorting to adding a fake attribute called something like
entityType
, and - without adversely affecting performance by using KVO/KVC tricks such as introducing
-(NSString*)typeOfEntity
or similar?
I currently have:
TradeDocument
as an abstract entity, withQuoteTradeDocument
andInvoiceTradeDocument
as entities based on it.
I want to display entity type and/or allow NSTableView
to be sorted based on this.
I use Cocoa Bindings on OS X.
Note: I am explicitly trying to avoid faulting each object.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Ivan,
抽象实体的唯一限制是您无法实例化它。您仍然可以获取它们。然后,测试每个托管对象属于哪个子类是一个相当简单的问题。
按类型排序不是排序描述符可以执行的操作,而是函数可以执行的操作,如
-sortUsingFunction:context:
。安德鲁
Ivan,
The only limit with an abstract entity is that you can't instantiate one. You can still fetch them. Then it is a rather simple matter of testing against which subclass each managed object is.
Sorting on type is not something a sort descriptor can do but a function can, as with
-sortUsingFunction:context:
.Andrew