NSPredicate在NSFetchedResultsController中表现奇怪 [英] NSPredicate acting strange in NSFetchedResultsController

查看:212
本文介绍了NSPredicate在NSFetchedResultsController中表现奇怪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这应该很简单,但它的行为很奇怪。

I feel as if this should be very simple, but it's behaving strangely.

我有3个实体,有这样的关系

I have 3 entities, with a relationship as such

实体A < - >>实体B <实体C

Entity A <-->> Entity B <<--> Entity C

我有一个NSFetchedResults控制器, m尝试使用以下谓词过滤实体A的结果。

I have an NSFetchedResults controller and I'm trying to filter the results of Entity A using the following predicate.

[NSPredicate predicateWithFormat:@"NONE entityB.entityC == %@", self.entityC];

当我尝试运行应用程序时,输出没有显示任何结果。我可以稍微改变谓词:

When I try and run the app, the output shows no results. I can alter the predicate slightly to:

[NSPredicate predicateWithFormat:@"ANY entityB.entityC == %@", self.entityC];

它只显示我想要过滤掉的结果。

And it shows me only the results that I want it to filter out.

为什么会发生这种情况?

Why is this happening?

推荐答案

我想你可能需要 SUBQUERY 表达式:

I think you may want a SUBQUERY expression:

@"SUBQUERY(entityB, $x, $x.entityC == %@).@count == 0"

虽然,它可能工作:

@"NOT (ANY entityB.entityC == %@)"

(注意:我没有测试第二个选项)

(note: I haven't tested the second option)

这篇关于NSPredicate在NSFetchedResultsController中表现奇怪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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