I have a Core Data model in which a Task object includes an optional to-many excludedOccurrences relationship. One of the properties of excludedOccurrences is the launch, which is an NSDate object. An ExcludedOccurrence object has an inverse binding relation to a single Task object.
To receive tasks for the specified day, I need to make sure that the specified day is not displayed as the start property of any ExcludedOccurrence object. Therefore, one of the sub-predicates that I am trying to use is
NSPredicate *occurrenceIsNotExcludedPredicate = [NSPredicate predicateWithFormat: @"(ALL excludedOccurrences.start != %@))", today];
where today is the NSDate object for today, including only the components of the day, month, and year. All properties for triggering excluded occurrences also include the components of the day, month, and year.
Although this should be good, at least for reading the documentation for Core Data and NSPredicate, I get the following error message:
Application termination due to an uncaught exception "NSInvalidArgumentException", reason: "Unsupported predicate
If I use an equivalent predicate
NSPredicate *occurrenceIsNotExcludedPredicate = [NSPredicate predicateWithFormat: @"!(ANY excludedOccurrences.start == %@))", today];
an exception is not thrown, however, the code does not work as expected: an exception from this list that should not be excluded.
I'm also not sure how to test for case excludedOccurrences == nil: the following predicate
NSPredicate *nilPredicate = [NSPredicate predicateWithFormat: @"(excludedOccurrences == nil)"];
raises an exception at runtime
to-many is not allowed here
However, since the excludedOccurrences relationship is optional, I also need to check if it is.
How can I handle this? Thank you in advance.