R – Embedding a predefined SQLITE doc in Core Data Application

cocoacore-data

Thanks for the help. I have a woking Core Data doc based app. that solely supports SQLITE docs. I would like to distribute the application with a previously created database document with predefined data embedded in the application bundle.

How do I instruct the application to run the embedded file at runtime?

thanks.

-paul.

Best Answer

Generally, what you'd do is store a copy of the file in the Resources directory of your application bundle. From there, it depends on what kind of application you have. If it's a single document application (like iPhoto, for example), You could copy the file to the ~/Application Support/Your Application directory so that your app will open it by default.

Take a look inside the application delegate class (I'm assuming you're using the template provided with Xcode?) to see how it generates the path to the application file. You basically just have to make sure that the file exists at that path when the application starts up.

In this case, NSFileManager and the pathForResource:ofType: method of NSBundle are your friends.

Related Topic