tl;dr: type something here that won't crash if birthDate is nil:
I have an entity with a birthDate attribute and a fetched property with the following predicate, typed straight into the xcdatamodel file:
$FETCH_SOURCE.birthDate > birthDate
This happily returns a list of managed objects older than FETCH_SOURCE (the managed object where the fetch request is happening). But birthDate is optional, and if the birthDate for FETCH_SOURCE is nil...
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'can't use NULL on left hand side'
Note that it's fine if the attribute is nil for the object being compared. If I swap the arguments of the predicate:
birthDate < $FETCH_SOURCE.birthDate
...I get the same error. Trying to test it for nil:
(birthDate != nil AND birthDate < $FETCH_SOURCE.birthDate)
...gives...
'NSInvalidArgumentException', reason: 'illegal comparison with NULL'
Google hasn't heard of either of those errors so I'm thinking this is a recent state of affairs. The problem remains when it's a String being compared for equivalence, or whatever. Is there a way to fix this in the predicate so it correctly returns an empty list? Thanks.
Edit: To be clear, the question is whether it's possible to fix this crash in the predicate in the xcdatamodel file.
Update: The crash specifically happens when the Relationship fault for the NSFetchedPropertyDescription is triggered by trying to read anything about it, presumably because it doesn't attempt to run the predicate till then. It isn't nil however, and can be checked for nil without crashing.