Basic data ANY BETWEEN the predicate

I am trying to create an NSPredicate to search for "projects" containing "sessions" within a specific date range. I tried this first:

[NSPredicate predicateWithFormat:@"ANY sessions.date BETWEEN {$STARTDATE, $ENDDATE}"]; 

But I get an exception:

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'to-many key not allowed here' 

BETWEEN does not seem to work with ANYONE in this way. I am also limited to using () and AND clauses that I cannot use something like:

 [NSPredicate predicateWithFormat:@"ANY (sessions.date > $STARTDATE && sessions.date < $ENDDATE)"]; 

If I try, I get a parsing error. And, of course, session.date is really a collection, so ANDing seems to have little meaning.

How can i do this?

thanks

UPDATE: Please note that this is:

 [NSPredicate predicateWithFormat:@"ANY sessions.date > $STARTDATE && ANY sessions.date < $ENDDATE"]; 

Incorrect because it returns a project in which the session is longer than the start date and the other session is less than the end date, but there is no session between them.

+4
source share
1 answer

I think this is the case when you need a SUBQUERY expression:

 [NSPredicate predicateWithFormat:@"SUBQUERY(sessions, $s, $s.date BETWEEN {$STARTDATE, $ENDDATE}) .@count > 0"]; 
+11
source

Source: https://habr.com/ru/post/1306813/


All Articles