问题描述
我已经阅读了NSPredicate文档,无法将其全部包裹起来。我能理解的简单谓词,但现在如何为以下情况创建谓词:
I've read the NSPredicate documentation and couldn't wrap my head around it all the way. Simple predicates I can understand, but now how do I create a predicate for the following situation:
我有一个Foo对象数组。在Foo类中,其中一个iVars是Bar对象的NSMutableArray。我需要过滤Foo对象的数组,以获得在其数组中具有特定Bar对象的对象。如何?
I have an array of Foo objects. In the Foo class, one of the iVars is an NSMutableArray of Bar objects. I need to filter the array of Foo objects to get those that have a particular Bar object in its array. How?
此外,是否更容易(或可能)一次找到多个Bar对象,或者组合多个谓词,每个谓词都搜索特定的Bar?
Also, is it any easier (or possible) to find multiple Bar objects at once, or to combine several predicates that each search for a particular Bar?
推荐答案
我找到了我要找的东西:
I've found what I'm looking for:
@class Foo {
int var1;
NSArray *barObjs;
}
predicate = @"var1 == 5 AND ANY barObjs.id == 5";
这篇关于NSPredicate可以在另一个数组中的对象所拥有的数组中搜索对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!