I have a list of items in an entity in Core Data on the iphone all of them have an item_id integer attribute. I need to return the highest numbered item_id and the lowest numbered item_id that are in the table with one fetch request. I do not have any knowledge of what those numbers might be as they do not start at 0 and go up.
What would be the best way to accomplish this? Again, I know I can do it with 2 separate fetch requests, is there a way to do it with just one?
That’s a tricky one to do in only ONE fetch. I would do two fetches using the MAX and MIN functions / expressions. e.g.
If you absolutely have to do it in ONE fetch then I can only think to do a fetchAll and sort by the id, then get the first and last via:
Update 1:
Looks like this guy has a solution:
http://useyourloaf.com/blog/2012/1/19/core-data-queries-using-expressions.html