Core Data Predicate Filter By Today's Date

Hello

I am using a SwiftUI @FetchRequest to displays Core Data items, one of the properties of the entity is date, and I want to filter items by today's Date, this is the @FetchRequest:

    @FetchRequest(
        entity: Book.entity(),
        sortDescriptors: [NSSortDescriptor(keyPath: \Book.date, ascending: true)],
        predicate: NSPredicate(format: "date == %@"),
        animation: .default)
    var books: FetchedResults<Book>

How do I complete the NSPredicate to make it work? (I know that there are no arguments in the predicate yet)

Thank You!

I've used predicates like:

let predicate = NSPredicate(format: "creationDate >= %@", startDate as CVarArg)

But beware when comparing dates for equality... remember what a Date is (a date and a time)... so you probably don't want that!
e.g. try a comparison where the stored date is >= the start of today.

Core Data Predicate Filter By Today's Date
 
 
Q