How to sort based on computed value from multiple Core Data attributes

I am trying to create a sort descriptor to query a basic data selection that will retrieve objects that are ordered by a computed value (for example, the sum of two or more attributes). Is it possible? Thanks in advance.

+1
source share
1 answer

In the "Master Data Programming Guide":

You cannot get using a predicate based on transient properties (although you can use transient properties to filter in memory yourself) .... To summarize, however, if you select directly, you should usually not add predicates based on Objective -C or sort the descriptors for the query to fetch. Instead, you should apply them to the selection results.

Thus, sorting by the calculated value seems impossible. You must pre-compute the sort value and store it as a (non-transitional) attribute in your objects.

+4
source

Source: https://habr.com/ru/post/1792776/


All Articles