It has been a while since I asked this question, and I think I went in a different direction with what I was doing, but there are some possibilities that I understand now to solve what I wanted at that time:
- In order for the visible property method to work recursively, instead of making a format predicate, do this. This can be done like this:
- (BOOL) isVisible {
return visible && [parent isVisible];
}
id filtered = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"visible == YES"]];
- Use block predicates instead of format predicates to perform recursive traversal:
[array filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
id obj = evaluatedObject;
while (obj) {
if (![obj isVisible]) return NO;
obj = [obj parent];
}
return YES;
}]];
Or a combination of the two (which would be the most reliable and readable, I think).
source
share