NSSortDescriptor和一对多关系 [英] NSSortDescriptor and to-many relationships

查看:156
本文介绍了NSSortDescriptor和一对多关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种类型的拒绝:位置和历史记录项。
我试图获取附加到任何历史项目的位置,所以我的位置的获取谓词是history。@ count> 0,这很好。

I have two types of objections: locations and history items. I'm trying to fetch locations which are attached to any history item, so my fetch predicate for the location is "history.@count > 0", which works fine.

我还希望通过NSSortDescriptor按照最近的历史项目的日期对位置对象进行排序,根据我可以证明的是history。@ max.time,但是这会抛出以下错误:

I'd also like to sort the location objects with an NSSortDescriptor by the date of their latest history item, which as far as I can make out would be "history.@max.time", this however throws the following error:


*** Terminating app due to uncaught exception 'NSInvalidArgumentException',
    reason: 'Keypath containing KVC aggregate where there shouldn't be one;
    failed to handle history.@max.time'

Halp plox?

Halp plox?

推荐答案

AFAIK,您只能使用收集操作符,在键值编码编程指南,用于您的排序描述符的关键路径,其中包含集合 NSArray NSSet NSDictionary )。

AFAIK, you must only use collection operators, described in the Key-Value Coding Programming Guide, for the key paths of your sort descriptors with collections (NSArray, NSSet, NSDictionary).

不能使用集合运算符作为排序描述符的关键路径fetch请求( NSFetchRequest )。

You must not use collection operators for the key paths of your sort descriptors with fetch requests (NSFetchRequest).

@kdbdallas正确使用集合运算符对 NSArray 。他不是用它来指定获取请求的排序描述符。

@kdbdallas correctly uses a collection operator to sort an NSArray. He is not using it to specify the sort descriptor of a fetch request.

虽然如果集合操作符用于指定要进行排序的关键路径要求。请通过 http://bugreport.apple.com/ 提交此功能请求。报告的次数越多,他们就越有可能支持它。

It'd be sweet though if collection operators worked for specifying the key paths by which to sort fetch requests. Please submit this feature request at http://bugreport.apple.com/. The more it's reported, the more likely they'll support it.

这篇关于NSSortDescriptor和一对多关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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