Is there a way to configure NSPredicate to compare dates?
Essentially, I have a photo object that has NSDate, lastViewed.
I would like to configure NSPredicate, which will return all Photo objects that were viewed most recently than the specified time period - usually two days.
I get the past date as follows:
NSTimeInterval secondsPast = -172800;
NSDate * twoDaysPast = [NSDate dateWithTimeInterval: secondsPast sinceDate: [NSDate date]]; And setting up NSPredicate this way:
request.predicate = [NSPredicate predicateWithFormat:@"lastViewed > %@", twoDaysPast];
However, I am not getting any results, and I do not quite understand why.
I know that all my objects with a photo have a lastViewed set - now it is set to the default when the photo is added to Core Data, so by default I should see that each photo is created, since lastViewed will be later than my twoDaysPast NSDate .
Is it possible to directly compare two instances of NSDate this way?
source share