Predicate with Dates #368

Closed
opened 2025-12-29 15:30:10 +01:00 by adam · 2 comments
Owner

Originally created by @llYunall on GitHub (Jul 15, 2021).

Hello,

I'm trying to do a NSPredicate with two dates and it gives me an error all the time.

Captura de pantalla 2021-07-15 a las 19 37 32

This is the code that I'm using:

Captura de pantalla 2021-07-15 a las 19 41 27

Do you know how can I use a Date variable in the predicate?

Thanks!

Originally created by @llYunall on GitHub (Jul 15, 2021). Hello, I'm trying to do a NSPredicate with two dates and it gives me an error all the time. <img width="1677" alt="Captura de pantalla 2021-07-15 a las 19 37 32" src="https://user-images.githubusercontent.com/87494445/125832511-c4c5a431-7a45-407e-8d43-2fb5f154a1f7.png"> This is the code that I'm using: <img width="1578" alt="Captura de pantalla 2021-07-15 a las 19 41 27" src="https://user-images.githubusercontent.com/87494445/125832955-ac9ce8ed-cf9a-45fa-a555-8ca4bc9b17cd.png"> Do you know how can I use a Date variable in the predicate? Thanks!
adam closed this issue 2025-12-29 15:30:10 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Jul 20, 2021):

You don't need to use an NSPredicate. It will mess up the generic type resolution. I also recommend the query builder syntax instead:

let smallFlush = try CoreStoreDefaults.dataStack.queryValue(
    From<Statistic>()
        .select(Int.self, .count(\.id))
        .where(
            combinedByAnd: \.localDate >= startDate, 
                \.localDate >= endDate,
                (\.device ~ \.bluetoothUUID) == bluetoothUUID,
                \.flushType == "0"
        )
)
@JohnEstropia commented on GitHub (Jul 20, 2021): You don't need to use an `NSPredicate`. It will mess up the generic type resolution. I also recommend the query builder syntax instead: ```swift let smallFlush = try CoreStoreDefaults.dataStack.queryValue( From<Statistic>() .select(Int.self, .count(\.id)) .where( combinedByAnd: \.localDate >= startDate, \.localDate >= endDate, (\.device ~ \.bluetoothUUID) == bluetoothUUID, \.flushType == "0" ) ) ```
Author
Owner

@llYunall commented on GitHub (Jul 20, 2021):

Perfect! Thanks a lot :)

@llYunall commented on GitHub (Jul 20, 2021): Perfect! Thanks a lot :)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#368