0

I have a NSPredicate to use searching Core Data:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"objID == %@ AND createDate >= %@ AND createDate <= %@",self.objID, self.fromDate, self.toDate];

I want to expand this predicate to include the date range or if the "createDate" is nil. I'm not that familiar with SQL type searches.

Basiclly, I want to find all Core Data entities with objID and within the date range or nil.

if (objID == X && ((dateRange >= fromDate && dateRange <= toDate) || dateRange == nil))

How can I do it?

Padin215
  • 7,444
  • 13
  • 65
  • 103

1 Answers1

1
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"objID == %@ AND (createDate >= %@ AND createDate <= %@ OR createDate = nil)",self.objID, self.fromDate, self.toDate];

I've just added OR createDate = nil.

Check this answer. Christopher Pickslay said, you can use "nil" or "NULL", but not "NIL".

Community
  • 1
  • 1
Valentin Shamardin
  • 3,569
  • 4
  • 34
  • 51