Take the 2-minute tour ×

I'm working on a Core Data app (for iPhone 3.0, though I don't think that really makes a difference here) and it will need to ship with a "starter" database filled with data. With SQLite, I would just have the App copy the populated database from the bundle into the App's documents directory on first launch and then load that database - all the information would come along with it and we'd be ready to go. But with Core Data, I'm not really sure if I can just save the Persistent store to the App bundle and copy it before having Core Data start doing its thing. Will this cause any problems? There is quite a bit of initial data, so I don't want to package it in another format and have to parse through it.

share|improve this question
Hello Zaph could you clarify that please? Checking the modified file stamp I see that the file is always modified regardless of the extension. How do you mean that Xcode changes the file contents? –  Max MacLeod Oct 22 '10 at 10:25
add comment

2 Answers

up vote 13 down vote accepted

Yes, you can copy over a pre-populated persistent store.

I created a Mac app that populates a store. It is copied into my bundle and at start, copied to the Docs directory. This works fine. I am told the Core Data Books example was developed the same way.

Please note this doesn't mean you can just copy over any old SQLite file. It has to be a Core Data persistent store, though I think you understand that based on your question.

share|improve this answer
Do you think it's ok to programatically populate the persistent store on my App's first run? Wouldn't this make my app considerably smaller to transfer since I would have to a while SQLite database included? –  leolobato Sep 1 '09 at 13:17
If your app can do this quickly, without pissing off a waiting user, then that seems like a fine way to do it. –  Hunter Sep 1 '09 at 22:33
Be careful. Unless your data can be generated algorithmically, it seems that the file-size savings you get by populating your data at runtime would be offset by the amount of data-populating code you need to include in your application. –  Chris Gillum Dec 21 '09 at 5:25
IS there any sample code of this mac app you created? Or where did you look for resources when you wrote the mac app –  banditKing Jan 10 '12 at 23:59
add comment

Actually there is a trick: you must name the file you are going to copy over with an extension other than ".sqlite", ".bin" will do. Otherwise Xcode will change the contents of the file when it copies it into the app during the build phase and it won't load.

share|improve this answer
add comment

Your Answer


