且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

仅按日期时间/日期选择器中的日期快速过滤

更新时间:2023-01-29 08:28:33

如果要过滤所选中的记录,则必须应用带有开始日期和结束日期的谓词>

If you want to filter the records which are in the selected day you have to apply a predicate with start and end date

let startDate = Calendar.current.startOfDay(for: calendar.selectedDate)
let endDate = Calendar.current.date(byAdding: .day, value: 1, to: startDate)
let predicate = NSPredicate(format: "date >= %@ AND date < %@", startDate as NSDate, endDate as NSDate)