As an alternative to Martin R's answer, you can use a block predicate instead. Something like that:
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary * bindings) { GrandParent *grandparent = evaluatedObject; for (Parent *parent in grandparent.parents) for (Child *child in parent.children) if (child.age == 10) return YES return NO; }];
Assuming GrandParent , Parent and Child are the corresponding class names for different objects.
Personally, I prefer this form because I always feel with a string predicate that I mix languages ββin code, which, in my opinion, makes it less readable. The choice is obviously up to you, though.
Update: After re-reading the question, I now understand that the condition was more complex than I originally thought. I updated my answer to the loop over parents and children, but Martin R's answer is now much simpler. However, this is a possible solution to consider.
source share