I’m creating a timeclock application where there is a ClockPunch NSManagedObject model with properties representing a clockin and clockout punch. Each ClockPunch instance has a relationship with an Employee in the Employees model (which also has a one-to-many relationship with each punch). I want to be able to write an NSPredicate that will give me the employee with their most recent clockin punch. I can then determine if they are clockedin or clocked out by whether or not they have a clockout punch to match. I do not want to pull all the punches in and then sort them, cause there could be 1000’s for each employee. What should I do?
My Model looks like this
Employees<->>ClockPunches
I tried something very similar recently like this. I tried finding the registration with the maximum date.
You can find more details on this page. https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreData/Articles/cdFetching.html
However the part that I’m still missing is how to only look into the registrations of a specific employee… I tried combining the request setting an NSPredicate but somehow they can’t be used together.
NOTE: I’m using restkit for my coredata access, follow the link to get a pure core data example (only small part of code is different)