views:

1149

answers:

3

Hi! I'm doing an iPhone application. In this app, I just want to have a database to be used as a looked up table for values in my app. The only thing the database will do was to supply me the values I needed depending on the query of the program. It won't do any addition or deletion in the database. My question was how do I initialize a default data on the application using CoreData. So that when the program starts It already had all the values needed.

If you have other suggestions of what is better do or what are other alternatives, please tell me.

Thanks.

A: 

I would write a tool that populates a database with the data you want in it, generate the db at build time and stuff it in your resources folder. If you are not going to write to it you can just leave it there and access it directly, if you ever did want to write to it you would need to copy it somewhere you are allowed to write (like the documents folder).

Louis Gerbarg
+5  A: 

I would create a simple Mac application, starting from the template for a Core Data document-based application. Copy your existing .xcdatamodel over the default one in the project (or add the new data model and be sure to rename anywhere that refers to the default model). Open up the XIB file for the document window in Interface Builder and drag the Core Data Entity item into it from the Interface Builder library inspector. From the resulting dialog, choose an entity to display and select an interface to display it in.

What this will do is create a fully functional interface for adding, removing, or editing the properties of that entity type. Everything should be hooked up via Cocoa Bindings so that you don't need to write a line of code for this to work. You can add interfaces for each entity type in your model this way.

This will let you quickly enter and edit data within a Core Data document, which you can then save out to disk and add as a resource to your iPhone application. The SQLite database structures are fully compatible between the desktop and iPhone Core Data implementations, so I've found that this is a quick and easy way of testing your iPhone Core Data code.

Brad Larson
A: 

Which file represents the core data document? I created a mac app and entered some data. Just dont know where the sqllite db is located? Any suggestions?

David

David
Hey, I saw you asked something similar [here](http://stackoverflow.com/questions/2202505/where-is-the-proper-place-to-initialize-data-in-a-core-data-store/3429227#3429227). You probably want to click 'Ask a Question' at the top of the page, and post your question there.
Chacha102