This is a little more complicated then just
NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"startDate >= %@ AND endDate <= %@\", startDay,
While the proposed solution is correct, it is also quite verbose. I have re-implemented it in Swift 3.0:
import Foundation
extension NSPredicate {
static func filter(key: String, onDayRangeForDate date: Date, calendar: Calendar = Calendar(identifier: .gregorian)) -> NSPredicate {
let dateComponents = calendar.dateComponents([.day, .month, .year], from: date)
let startOfDay = calendar.date(from: dateComponents)!
let offsetComponents = NSDateComponents()
offsetComponents.day = 1
let endOfDay = calendar.date(byAdding: offsetComponents as DateComponents, to: startOfDay)!
return NSPredicate(format: "\(key) >= %@ && \(key) < %@",
startOfDay as NSDate, endOfDay as NSDate)
}
}