Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a large amount of data from Core Data

I have such a task in front of me: there are more than 10,000 records in the database, I need to display them in the table view, but I can not take all 10,000 and store in the array how to organize the work, for example, when scrolling 100 records in a table view, Download the next 100 entries from the database.

I found things like fetchLimit and fetchOffset, but I still did not understand how to use them for my task.

What would you tell me?

like image 544
dmitriy koliush Avatar asked Oct 27 '25 07:10

dmitriy koliush


1 Answers

I believe if you are using Core Data and you need UITableView you should defiantly use NSFetched​Results​Controller.

From Apple documentation.

You use a fetched results controller to efficiently manage the results returned from a Core Data fetch request to provide data for a UITable​View object.

By using of this approach you going to use by default Cache that will improve performance. Also with this you going to dynamically update UITableView when some of the records in Core Data will be changed or be added.

Also to fetch data by portion you can modify NSFetchRequest and setfetchLimit for each request.

Example of the simple NSFetched​Results​Controller implementation.

like image 150
Oleg Gordiichuk Avatar answered Oct 28 '25 19:10

Oleg Gordiichuk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!