realm-swift
realm-swift copied to clipboard
NSPredicate that filters on the current time
I'd like to have a way to create a NSPredicate (for use in Realm with Collection notifications) that filters records based on the current time.
NOT the time when the predicate was created:
NSPredicate(format: "endsAt < %@", NSDate())
But the time when the predicate is evaluated is something like this:
NSPredicate(format: "endsAt < now()")
The predicate language is part of Apple's SDKs so we're not able to extend it as you suggest. It would be possible to instead provide a value that can be substituted into the predicate that Realm would recognize as being a placeholder for the current time.
I don't want to extend predicate language, NSPredicate(format: "endsAt < now()") is a valid predicate for iOS8+.
But provide a value that can be substituted is a good workaround.
Ah, so it is! I didn't see it mentioned when I re-skimmed Apple's Predicate Programming Guide, but now I see that it is in the list of functions in the BNF definition.