I have an entity that stores information about my photos in core data. One of the attributes of this entity is “lastSeen”, which stores the date and time when the picture was last seen.
I would like to query my database to see only the pictures seen in the last 48 hours. How could I do that?
I know I need to use some method like timeIntervalSinceNow and NSPredicte, but Im not sure how the syntax of this query would look like.
Any help is appreciated.
Thanks!
ADDENDUM
Here’s how I created the viewDate attribute.
In
myProjectName.xcdatamodeldselect the Photo entity.Add an attribute with name ‘viewDate’ and type ‘Date’.
Select it, and hit edit > copy.
Go to
Photo.h, and click at the place where you want to generate the property.Choose this special paste option:
edit > ‘Paste Attribute Interface’.
It should generate this line of code:
The same in
Photo.mto generate:I set the date in my PictureViewController’s loadView like this: