@Query using Predicate and DateComponents (multidatecomponents)

I am trying to build a CRUD app using a multidatepicker.
The Apple documentation for multidatepicker uses
Set<DateComponents> = [ ]
The problem is how to retrieve records for the current date.
The debugger has the folllowing error;

Query encountered an error: Unsupported Predicate: Captured/constant values of type DateComponents' are not supported

Here is my syntax for the @Query. I have a class called Planner and a property called dates (multidatepicker) and a 2nd property called period.

@Query var planner: [Planner]

init() {
   let dateComp = DateComponents(calendar: Calendar.current, year: 2025, month: 4, day: 19)
    
    _planner = Query(
        filter:  #Predicate { $0.dates.contains(dateComp) },
        sort: \Planner.period
    )
}

The code compiles but there is a query error and I can't find any documentation or examples of the correct syntax.

Any help is greatly appreciated!

Hi JELI, I found your post just today while looking for a solution to a similar problem. There is likely an easier way than what I ended up doing, and I'd like to know it too! In the meantime I pulled dates from Calendar components and used that in the predicate instead of Calendar references:

In my type:

    static var forwardSort = SortDescriptor(\SavedItem.timeStamp, order: .forward)
    
    //thingMemory.items.filter({ Calendar.current.isDate($0.timestamp, inSameDayAs:date) }).sorted(by: { $0.timestamp > $1.timestamp })
    static func makeDateFilter(thisDate:Date) -> FetchDescriptor<SavedItem> {
    
        let calendar = Calendar.current
        let dateFrom = calendar.startOfDay(for: thisDate)
        
        //TODO: Fix the !!!
        let dateTo = calendar.date(byAdding: .day, value: 1, to: dateFrom)!
        
        let datePredicate = #Predicate<SavedItem> { item in
            item.timeStamp > dateFrom && item.timeStamp < dateTo
        }
//
        var descriptor = FetchDescriptor<SavedItem>(sortBy: [forwardSort])
        descriptor.predicate = datePredicate
        
       return descriptor
    }

In My View

    @State var selectedDate:Date
    
    @Query private var items: [SavedItem]
    init(date:Date) {
        self.selectedDate = date
        _items = Query(SavedItem.makeDateFilter(thisDate: selectedDate))
    }

The links I used: