Apologies if this is a duplicate, 20 minutes of searching didn\'t yield this exact situation or a solution.
I have a Core Data stack with three classes XClass<
It seems that NSPredicate objects violently when you use collection operators in the predicate string for the SUBQUERY. It also appears that you cannot operate on a collection in the subquery predicate. That is unless the variable represents a collection in the predicate.
BAD: SUBQUERY(yObjects, $y, $y.zObjects == NIL) > 0
OK: SUBQUERY(yObjects, $y, SUBQUERY($y.zObjects $z, $z == NIL) > 0) > 0
The following expression will add all non-nil objects to the filtered collection returned by the SUBQUERY. In other words, the returned collection will contain all instances of XClass with instantiations of ZClass.
[NSPredicate predicateWithFormat:@"yObjects.@count > 0 AND (SUBQUERY(yObjects, $y, (SUBQUERY($y.zObjects, $z, $z != NIL).@count > 0)).count > 0)"];