Reputation: 1396
For example, your FRC fetches a news feed and groups the articles into sections by date of publication.
And then you want to limit the size of each section to be up to 10 articles each.
One option I’ve considered is having separate NSFetchedResultsControllers for each day and setting a fetch limit. But that seems unnecessary as the UI only really needs a single FRC (not to mention that the number of days is unbounded).
Edit:
I’m using a diffable data source snapshot.
Upvotes: 0
Views: 79
Reputation: 70946
If it was me, I'd leave the NSFetchedResultsController
alone for this and handle it in the table view. Implement tableView(_:, numberOfRowsInSection:)
so that it never returns a value greater than 10. Then the table will never ask for more than 10 rows in a section, and your UI will be as you want.
Upvotes: 1
Reputation: 1396
Since I’m using a diffable data source snapshot, I am able to take the snapshot I receive in the FRC delegate callback and use it to create a new snapshot, keeping only the first K items in a section.
Upvotes: 0