Core Data ANY BETWEEN predicate
Posted
by Mike Weller
on Stack Overflow
See other posts from Stack Overflow
or by Mike Weller
Published on 2010-04-13T15:04:17Z
Indexed on
2010/04/13
15:13 UTC
Read the original article
Hit count: 407
I'm trying to create an NSPredicate to find 'projects' that contain 'sessions' within a certain date range. I tried this at 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'
It seems BETWEEN does not work with ANY in this way. I'm also limited in use of () and AND clauses meaning I can't use something like:
[NSPredicate predicateWithFormat:@"ANY (sessions.date > $STARTDATE && sessions.date < $ENDDATE)"];
If I try that I get a parse error.
How can I do this?
Thanks
UPDATE: Note that this:
[NSPredicate predicateWithFormat:@"ANY sessions.date > $STARTDATE && ANY sessions.date < $ENDDATE"];
Is incorrect because it returns a project where there is a session greater than the start date and another session less than the end date but no session in between.
© Stack Overflow or respective owner