Core Data NSPredicate with to-Many Relationship

南楼画角 提交于 2019-11-27 22:34:02

Core Data predicates with "NOT ANY" do not work (that seem to be a Core Data bug). Actually

[NSPredicate predicateWithFormat:@"NOT(ANY couponOwners.userId = %@)", @"4"];

returns the same result set as

[NSPredicate predicateWithFormat:@"ANY couponOwners.userId != %@", @"4"];

which is of course wrong. As a workaround, you can use a SUBQUERY:

[NSPredicate predicateWithFormat:@"SUBQUERY(couponOwners, $c, $c.userId == %@).@count == 0", @"4"]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!