Is it possible to sort by subclasses in an `NSFetchRequest` without adding additional attributes?

一世执手 提交于 2019-12-05 06:55:43

I think the answer is no.

Fetched and Sorting happens in the Store (for SQLLite store), so the attributes need to be part of the data model. From the core data programming guide (Persistent Store Features):

There are some interactions between fetching and the type of store. In the XML, binary, and in-memory stores, evaluation of the predicate and sort descriptors is performed in Objective-C with access to all Cocoa's functionality, including the comparison methods on NSString. The SQL store, on the other hand, compiles the predicate and sort descriptors to SQL and evaluates the result in the database itself. This is done primarily for performance, but it means that evaluation happens in a non-Cocoa environment, and so sort descriptors (or predicates) that rely on Cocoa cannot work.

also

In addition you cannot sort on transient properties using the SQLite store.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!