NONE or NOT ANY in Core Data predicates

  • For the purposes of this issue, I have two entities, Foo and Bar. Foo
    has a to-many relationship to Bar, called bars.

    My ultimate goal is to fetch those Foo objects that have certain
    properties, and which do *not* contain relationships to Bar objects
    that also have certain properties. The natural fetch request might be:

    [NSPredicate predicateWithFormat:@"(name like %@) AND NONE ((bars.x ==
    %d) AND ( like %@))",fooName,barsX,barsName];

    The Predicate Programming Guide (assuming I've read it correctly)
    appears to back up the use of NONE in core data predicates. However,
    testing seems to indicate that while ANY and ALL appear to work, NONE
    does not- nor does NOT in combination with ANY or ALL. The above
    predicate, and simpler tests with NOT ANY, NOT ALL, and NONE all fail
    with NSPredicate complaining that it cannot parse the format string.

    I've managed to work around this issue for now by fetching many more
    objects than I actually need and doing the tests on the resulting
    array. However, I imagine that if I could get the desired predicate to
    work, I'd get much better performance out of leveraging Core Data to
    do the filtering.

    Am I simply missing something trivial here? Is NONE/NOT ANY not
    actually working (either I'm misreading the documentation or it is
    incorrect)? Or should I be approaching this problem from some other
    - David T. Wilson
    Princeton Satellite Systems
previous month october 2007 next month
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        
Go to today