5

I am able to create the DataModel, Entities and Properties. How do I now create the DB? Do I have to create it manually making sure that all the properties and entities are mapped?

I am following the Recipes Core Data sample and have noticed a method in RecipesAppDelegate.m:

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
}

I can see a reference to the DB file here.

2
  • If you want an easy cheap way to look at or manage your SQLite Db you can use this firefox plugin. It's pretty full featured and the price is right, free. Commented Jun 22, 2009 at 13:33
  • What about pre-populating the database? Would it be best to link the SQL source in with the build process? For a large data store this seems like an unappealing option (having to rebuild each time). Commented Jun 24, 2009 at 22:28

1 Answer 1

5

When you create the persistent store coordinator, if you are using the SQLite persistent store type, the coordinator will automatically create the database for you if it does not already exist. You don't have to create the store file yourself.

EDIT: to clarify, the only thing you should be modifying is the Core Data object model (.xcdatamodel) file. An NSPersistentStoreCoordinator object, when it is created with a store file or the addPersistentStore: method is called on it, will do all the necessary setup of the backing store. This includes creating the file, any tables it may contain, etc.

Creating or modifying any type of persistent store yourself (especially SQLite stores) is completely unsupported by the SDK and the Core Data framework.

Sign up to request clarification or add additional context in comments.

2 Comments

You mean I should create the method above and the code will create the file? What about the tables and columns in the Database?
It's all taken care of by the object graph you designed in your data model. The persistent store coordinator will read that from your managed object model and modify its SQLite table directly. As a matter of fact, Apple's Core Data Programming Guide forbids you to interface directly with the SQLite store.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.