I came up with a solution to this using subquery, but I don't understand why what I was trying to do first didn't work.
Here's my data model. I'm fetching on Advice.
I can do the following as a predicate:
[NSPredicate predicateWithFormat:@"ANY conditions.terrain == %@", aTerrainObject];
that works fine, and returns any piece of advice where at least one of its conditions has that terrain type.
However, when I try to do this, it fails:
[NSPredicate predicateWithFormat:@"ANY conditions.terrain == nil"];
What I want to do is return any piece of advice where at least one of its conditions doesn't have a terrain type set.
However, the following does work:
[NSPredicate predicateWithFormat:@"SUBQUERY(conditions, $x, $x.terrain == nil).@count > 0"];
Can anyone explain why, when searching for nil, I can't use the ANY
syntax?