如何根据多个Core Data属性中的计算值进行排序 [英] How to sort based on a calculated value from multiple Core Data attributes

查看:166
本文介绍了如何根据多个Core Data属性中的计算值进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为核心数据获取请求创建一个排序描述符,以获取按计算值排序的对象(例如,两个或多个属性的总和)。这可能吗?提前感谢。

I'm trying to create a sort descriptor, for a core data fetch request, that will fetch objects that are ordered by a calculated value (e.g., the sum of two or more attributes). Is this possible? Thanks in advance.

推荐答案

从核心数据编程指南:


您不能使用基于瞬态属性的谓词获取
(虽然您可以使用瞬态属性在内存中过滤
)。 ...到
总结,但是,如果你直接执行fetch,你应该
通常不添加基于Objective-C的谓词或排序描述符到
获取请求。

You cannot fetch using a predicate based on transient properties (although you can use transient properties to filter in memory yourself). ... To summarize, though, if you execute a fetch directly, you should typically not add Objective-C-based predicates or sort descriptors to the fetch request. Instead you should apply these to the results of the fetch.

因此,按计算值排序似乎不可能。您必须预先计算排序值,并将其作为(非瞬态)属性存储在对象中。

So sorting by a calculated value seems not to be possible. You have to pre-calculate the sorting value and store it as (non-transient) attribute in your objects.

这篇关于如何根据多个Core Data属性中的计算值进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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