Keypath error with Core Data SUBQUERY and NSFetchedResultsController

后端 未结 1 919
有刺的猬
有刺的猬 2021-01-16 10:11

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<

相关标签:
1条回答
  • 2021-01-16 10:39

    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)"];
    
    0 讨论(0)
提交回复
热议问题