xcode iOS:一对一和多对多关系的“@count == 0”的 NSPredicate

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10277801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:03:24  来源:igfitidea点击:

iOS: NSPredicate for "@count == 0" for both to-one and to-many relationships

iosxcodecore-datanspredicatensmanagedobject

提问by powertoold

I'd like to write a single NSPredicatethat would work for both to-one and to-many relationships:

我想写一首NSPredicate既适用于一对多关系又适用于多对多关系的单曲:

1) I have an NSMutableArraythat will run the filterUsingPredicatemethod

2) The NSPredicate will filter out a selected relationship that contain any objects in the relationship (again, for both to-one and to-many relationships).

1) 我有一个NSMutableArray将运行该filterUsingPredicate方法

2) NSPredicate 将过滤掉包含关系中任何对象的选定关系(同样,对于一对一和对多关系)。

I've tried something like predicateWithFormat:@"relationshipObjects.@count == 0", but this only seems to work for to-many relationships. Is there a similar predicate format that will work for both to-one and to-many relationships?

我试过类似的东西predicateWithFormat:@"relationshipObjects.@count == 0",但这似乎只适用于多对多关系。是否有类似的谓词格式适用于一对一和多对多关系?

采纳答案by Nikita Pestrov

I think, you can use check for nilhere.

我想,你可以在这里使用 check for nil

predicateWithFormat:@"relationshipOject != nil"