0

I'm currently working on an app which needs data. Exemple: A list of books. What is the best way to create a data base pre populated at first launch ? Or do we need to populate a core data base at its first launch ?

Thanks in advance for your help :)

Bobyblanco
  • 123
  • 12
  • 1
    http://stackoverflow.com/questions/11922800/coredata-deliver-setup-default-data – Adam Aug 14 '12 at 19:16
  • 1
    possible duplicate of [Any way to pre populate core data?](http://stackoverflow.com/questions/2230354/any-way-to-pre-populate-core-data) – Daniel Aug 14 '12 at 19:19

2 Answers2

0

You can store the "seed data" any way you like, text files, plists etc. and even in a database (presumably sqlite).

Then when starting up your app, check if the data already exists in your core data store. If not, import the file into your database.

You could also have a preconfigured database and copy that to the application documents directory to make it writable. This is a somewhat more involved approach, as you will have to regenerate this seed database each time your seed data or model changes.

Mundi
  • 79,884
  • 17
  • 117
  • 140
  • Thanks Mundi, So if i have understood, if i don't create a sqlite database for exemple, i can create the core data base at the first launch? How can we check if a range of data already exist in core data ? – Bobyblanco Aug 14 '12 at 12:26
  • That's simple. Just do a quick fetch and see if you get any results. – Mundi Aug 14 '12 at 14:37
0

In my apps I have a DB which I only use to read from (no writing), I include it in my bundle that is distributed. I then update the AppDelegate->persistentStoreCoordinator method to point to the correct location for my DB.

If I needed to write to the DB, then I would need to move it to the Documents directory prior to accessing it. And the changes to AppDelegate->persistentStoreCoordinator would not be needed.

Mark S.
  • 3,849
  • 4
  • 20
  • 22