I need to fetch data from CloudKit to add to the data source of a table view when the user scrolls all the way down to the bottom of the table view. How do I get the table view to trigger code to fetch the data from CloudKit? Is there a notification or an event that fires at that time?
I understand your goal is not to have to load all data first, but load on the fly ?
You can load batches of data, as described here
You can also use prefetching
Prefetching Data
If your table view relies on an expensive data loading process, you can improve your user experience by prefetching data before it is needed for display. Assign an object that conforms to the
UITableViewDataSourcePrefetching
protocol to the prefetchDataSource
property to receive notifications of when to prefetch data for cells.var prefetchDataSource: UITableViewDataSourcePrefetching?
The object that acts as the prefetching data source for the table view, receiving notifications of upcoming cell data requirements.
For a complete tutorial:
h ttps://andreygordeev.com/2017/02/20/uitableview-prefetching/
Other reading
h ttps://medium.com/capital-one-tech/boost-smooth-scrolling-with-ios-10-pre-fetching-api-818c25cd9c5d