Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftData #Predicate do not work with Date

Tags:

swiftdata

let startDate: Date = Date()
    let predicate = #Predicate<Trip> { session in
        session.startTime >= startDate
    }

Does anybody has this issue when #Predicate do not work on Date? I am getting unsupported predicate error. Any ideas to fix?

like image 629
Jan Kubny Avatar asked Aug 12 '26 07:08

Jan Kubny


1 Answers

Since date isn't yet available to be used on the #Predicate macro, in the meantime, the following workaround can be used:

@Query private var queriedTrips: [Trip]

// Create a computed property
var trips: [Trip] {
    let startDate: Date = Date()

    return queriedTrips.filter({ $0.startTime >= startDate })
}

While this may not be ideal, I don't think there's much we can do at the moment.

like image 92
yttrium Avatar answered Aug 15 '26 15:08

yttrium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!