使用NSFetchedresultController对“transient”字段进行排序 [英] Sorting on 'transient' fields with NSFetchedresultController
问题描述
有一种方法来使用'transient'字段或类似的东西,并以某种方式相应地与NSFetchedResultsController排序。我想要执行以下操作:
Is there a way to use a 'transient' field or something like that and in some way sort accordingly with a NSFetchedResultsController. I want to do the following:
我在数据库中有位置。当一个人打开列表,我想显示最近的地方在顶部,然后根据距离排序。但是很明显,这取决于用户的位置,所以我不能使用静态字段。我希望使用一个暂时字段,你可以使用的节头。
I have location of places in a database. When a person opens the list, I want to show the nearest place on top, an then sort accordingly to distance. But clearly,this depends on the users location, so I cannot use a static field. I was hoping to use a transient field, as you can use for the section headers.
有没有人可以给这个情况的解决方案或解决方法?
Is there anybody who can give a solution or workaround for this situation?
推荐答案
您不能在SQlite基本Core Data存储的提取请求中使用瞬态属性。
You cannot use a transient property in a fetch request for a SQlite base Core Data store.
请参阅获取托管对象:
您无法使用基于瞬态的谓词properties
(虽然你可以使用瞬态属性在内存中过滤
)。 ...总而言之,如果你直接执行一个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.
您可以使用临时属性 sectionNameKeyPath
,但即使这样,您仍然需要为基于持久属性的节创建第一个排序描述符。
You can use a transient property for sectionNameKeyPath
, but even then you need a first sort descriptor for the sections that is based on a persistent attribute.
可能是抓取所有对象,然后排序抓取的数组。但是,当然,你不再具有获取结果控制器的优势。
So the only workaround is probably to fetch all objects and then sort the fetched array. But then of course you don't have the advantages of a fetched results controller anymore.
这篇关于使用NSFetchedresultController对“transient”字段进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!