How can I compare dates within the predicate ? Currently I get "Global functions are not supported in this predicate" error
filter: #Predicate<Flashcard> { $0.nextReviewAt <= Date.now },
class Flashcard {
var nextReviewAt: Date
}
How can I compare dates within the predicate ? Currently I get "Global functions are not supported in this predicate" error
filter: #Predicate<Flashcard> { $0.nextReviewAt <= Date.now },
class Flashcard {
var nextReviewAt: Date
}
Use predicate as a static function
filter: predicate(),
static func predicate() -> Predicate<Flashcard> {
let now = Date()
return #Predicate<Flashcard> { $0.nextReviewAt <= now }
}
extract the Date.now to
let date = Date.now
Then, create your predicate using the constant date value. The Date.now is not a constant. This should fix the problem. It did in my test.