SUBQUERY in NSPredicate and NSInvalidArgumentException

I installed the following model in Core Data.

Book has a to-many relationship, called toBookOrders, with OrderBook entity. The inverse is called toBook.
Book has a BOOL value property called isSync.

I installed the following NSPredicate.

NSEntityDescription* entityDescription = [NSEntityDescription entityForName:@"Book" inManagedObjectContext:moc];
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"isSync == 0 AND SUBQUERY(toBookOrders, $x, $x.toBook == SELF)"];

Through this predicate, I need to capture only books that have not been synchronized, and their relative orders.

This is the error I am getting.

Application termination due to the uncaught exception "NSInvalidArgumentException", reason: "Unable to parse string format" isSync == 0 AND SUBQUERY (toBookOrders, $ x, $ x.toBook == SELF) "

Any ideas? Thank you in advance.

+5
source share
2 answers

Here is the gist of your problem:

@"isSync == 0 AND SUBQUERY(toBookOrders, $x, $x.toBook == SELF)"

If you divide this into two sub-products, as Scott suggests, you get:

  • isSync == 0
  • SUBQUERY(toBookOrders, $x, $x.toBook == SELF)

, SUBQUERY true false, . (), - , true false. , , , , AND . .

, :

@"isSync == 0 AND SUBQUERY(toBookOrders, $x, $x.toBook == SELF).@count > 0"

, , isSync , OrderBooks - .

+24

isSync == 0 SUBQUERY NSPredicate s, NSArray, [NSCompoundPredicate andPredicateWithSubpredicates:array], , NSFetchSpecification.

-2

All Articles