I have a simple data model with visitors (fName and lName) and visits (date, comment) in a 1-m relation. I'm trying to fetch all visitors for a particular day. In order to achieve this, I need to create a predicate to look for all entities having visits between the start of that day and its end. I have tried:
...
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "visitor")
let filter = "ANY visits.date >= %@ AND ANY visits.date < %@" // visits is the visitors relation to visits
let startTime = calendar.startOfDay(for: thisDay) as NSDate
let endTime = calendar.date(bySettingHour: 23, minute: 59, second: 59, of: thisDay)! as NSDate
fetchRequest.predicate = NSPredicate(format: filter, startTime, endTime)
The result are all visitors with visit dates at and after this day. Hence the second part of the compound predicate has no effect! I've also tried to combine the two conditions with the NSCompoundPredicate, but the result is the same. I've experimented with other than date types with the same compound predicate and these all worked well. So despite extensive searches in the Internet, I have no clue how to solve this simple query with predicates.
Any suggestions are most welcome!
ANY visits.date >= %@ AND ANY visits.date < %@
=>ANY (visits.date >= %@ AND visits.date < %@)
?