NSPredicate acting strange in NSFetchedResultsController

本小妞迷上赌 提交于 2019-12-11 02:24:58

问题


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

I have 3 entities, with a relationship as such

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

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?


回答1:


I think you may want a SUBQUERY expression:

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

though, it may work to do:

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

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



来源:https://stackoverflow.com/questions/2580875/nspredicate-acting-strange-in-nsfetchedresultscontroller

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