Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hookup or create Sqlite DB with Core data model in iPhone

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.

like image 452
Picflight Avatar asked Jun 20 '09 22:06

Picflight


1 Answers

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.

like image 96
Tim Avatar answered Nov 01 '22 10:11

Tim