Reputation: 31
I'm using Core Data with an NSFetchedResultsController. My data consists of many students and lesson dates. I set my Predicate and Sort Descriptors up to return a sorted lists of lessons for a particular student. I sort ascending or defending, and my table view is loaded and happy.
However, at times, I want to return only the previous two lessons, sorted ascending. How in the world can I construct a NSFetchRequest to only return an array of two items?
I've been trying to fool the table view by modifying rows and sections... and yes, it is getting tangled up and clunky.
It seems I need to nest NSFetchRequests inside of the NSFetchedResultsController. First fetching and getting the number of total items / sections. And then just getting the last two objects when sorting ascending. How do I limit the results to the last two items when I don't know how many items there are when setting up the NSFetchRequest?
Thanks
Upvotes: 0
Views: 167
Reputation: 70936
Just tell the fetch request how many you want:
[fetchRequest setFetchLimit:2];
Results will be sorted according to your sort descriptor(s), and you'll get the first two results.
Upvotes: 1