Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone core data preset

What is the best way to initialize Core Data database with content. My iPhone app will have a static database with products (data and images). How/where to store images, how to pre-populate database?

like image 436
xpepermint Avatar asked Feb 05 '26 02:02

xpepermint


1 Answers

Here is what I did:

  • Create the database inside the iPhone app
  • I created the model in XCode and do a query against the database (this creates the database)
  • My static data is a CSV file
  • Use a Ruby script to read the CSV file
  • Use the ruby gem sqlite3 to insert data into the database
  • Copy back into project

Alternative:

  • Store the CSV/XML file containing data inside the app
  • Parse it on startup and create your NSMAnagedObjects

Tools/Resources:

  • Base software for editing/viewing a sqlite3 database

Database Location: I'm afraid I don't remember it on the top of my head but when you use the simulator your application will be built and copied into a directory. I think the path to your application will be something like this. The database depending on how it is setup is usually in the Documents folder.

~User/Library/Application Settings/iOS Simulator/<version>/<app id>/
like image 154
willcodejavaforfood Avatar answered Feb 06 '26 18:02

willcodejavaforfood



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!