相关疑难解决方法(0)

核心数据,NSPredicate和to-many密钥

我有一个Core Data模型,其中Task实体包含一个可选的to-many关系excludedOccurrences.excludedOccurrences的一个属性是start,它是一个NSDate对象.ExcludedOccurrence实体与Task实体具有反向强制一对一关系.

为了获取指定日期的任务,我需要确保指定的日期不会显示为任何ExcludedOccurrence实体的start属性.因此,我试图使用的一个子谓词

NSPredicate *occurrenceIsNotExcludedPredicate = [NSPredicate predicateWithFormat: @"(ALL excludedOccurrences.start != %@))", today];
Run Code Online (Sandbox Code Playgroud)

今天是今天的NSDate对象,仅包括日,月和年组件.所有排除的事件启动属性也仅包括日,月和年组件.

虽然这应该没问题,至少阅读Core Data和NSPredicate的文档,但是我收到以下错误消息:

由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'不支持的谓词

如果我使用等效谓词

NSPredicate *occurrenceIsNotExcludedPredicate = [NSPredicate predicateWithFormat: @"!(ANY excludedOccurrences.start == %@))", today];
Run Code Online (Sandbox Code Playgroud)

没有抛出任何异常,但代码不能按预期工作:而是排除了今天不应排除的事件.

我不确定如何测试caseOccurrences == nil:以下谓词

NSPredicate *nilPredicate = [NSPredicate predicateWithFormat: @"(excludedOccurrences == nil)"];
Run Code Online (Sandbox Code Playgroud)

在运行时导致异常

这里不允许使用多个密钥

但是,由于excludedOccurrences关系是可选的,我还需要测试它是否为零.

我该如何处理?先感谢您.

iphone core-data nspredicate

42
推荐指数
3
解决办法
3万
查看次数

标签 统计

core-data ×1

iphone ×1

nspredicate ×1