-1

I have an application that display products. I have over 5 000 products and i want to display them in table view. The problem is that I cannot store this data in array, because it takes too much memory. I want to store my data locally so I decided to use Core Data.

How can I insert that large number of data in Core Data? Maybe there is an option in Xcode? If not, how can i handle this problem?

ShadeToD
  • 403
  • 9
  • 22

1 Answers1

1

Proceed in two stages.

  1. In stage one, create the core data database and store the 5000 objects in it. Now remove that code (or arrange so that you never run it again), and copy that database into your app bundle.

  2. So in stage two, your app launches, copies the database out to the documents folder (if it isn't there already), accesses it, and uses it.

Thus, when the end user actually comes to use your app, there's the database all prepared and ready to use instantly, because the user experiences only stage two.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Sounds like a good plan. Anyway how can i safely save over 5000 objects? Is it good idea to create my object and save it in a loop 5000 times? – ShadeToD May 08 '19 at 18:18
  • Why on earth not? 1, 5000, 5000000, who cares? This is exactly what a database is _for_. – matt May 08 '19 at 18:25
  • I thought it could be a problem when u read these objects for example from CSV file and u need to store them in array before u add them to coredata. So if u have tons of data u could run out of memory – ShadeToD May 08 '19 at 18:28