I want to create a NSPredicate with BETWEEN keyword for two dates:
my argument e_date is a CoreData Entity Property of type Date
let sd = DateComponents(calendar: Calendar.current,year: 2019, month: 1, day: 1).date!
let ed = DateComponents(calendar: Calendar.current,year: 2020, month: 1, day: 1).date!
let whenPredicate = NSPredicate(format: "e_date BETWEEN %@", [sd, ed])
I get a following exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "e_date BETWEEN %@"'
I have tried to cast arguments to Objective-C Types but still gets the same error.
let whenPredicate = NSPredicate(format: "e_date BETWEEN %@", [sd as NSDate, ed as NSDate])
let whenPredicate = NSPredicate(format: "e_date BETWEEN %@", [sd as NSDate, ed as NSDate] as NSArray)
What is a correct way to use NSPredicate with BETWEEN keyword?
* Updated *
I have done Clean Build Folderand the error has gone.
e_date > sd AND e_date < ed- Larmebetweenterminates with an exception. One more thing, NSPredicate doesn't know where it will be used, so it should parse correctly at this stage. - Blazej SLEBODA