views:

112

answers:

2

I am doing coredata app and i want to add the some data in TwitterClient.sqlite but it is created automatically in my appdelegate file like below . how can i add some data in coredata app.

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {

    if (persistentStoreCoordinator != nil) {
        return persistentStoreCoordinator;
    }


    NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"TwitterClient.sqlite"]];

    NSError *error;
    persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc]      initWithManagedObjectModel: [self managedObjectModel]];

    if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error])


    {
        // Handle error
    }   

    return persistentStoreCoordinator;

}
+4  A: 

Based on your questions here and here, it sounds like you're just getting started with Core Data. I'd highly recommend reading through the Getting Started with Core Data guide, as well as the Core Data Tutorial for iPhone OS, because Core Data can be a little complex for someone new to it. Additionally, you can look at the answers to these questions:

You have started to create your Core Data stack with the snippet of code posted above, but you'll need to set up the rest of it. You need to create a managed object model (your data model designed in Xcode), as well as create a managed object context to go along with your persistent store coordinator. These three elements work together to let you save data within your persistent store. Again, I highly recommend reading the above resources, which go into this in much greater detail.

Once you have your Core Data stack set up, you will be able to retrieve data from the managed object context using fetch requests (and / or a NSFetchedResultsController) and insert new data into the context by creating new NSManagedObjects that use one of the entity descriptions from your managed object model. If none of this makes sense, again I'd say that you should start with Apple's documentation linked above.

Brad Larson
A: 

If I understand your question properly then you want to ship your application with a Core Data persistent store (sqlite in this case) that already starts with some default data.

I just asked the same question: http://stackoverflow.com/questions/2018127/whats-the-correct-way-to-ship-static-read-only-data-in-core-data-persistent-st

In short, the options are usually: 1) put the default data in a plist file, then write code to add it the first time the application is run, or 2) use a utility in OS X that uses Core Data to create the sqlite file you want, then add the sqlite file as a resource in your project the way it's done in the Recipes sample code app.

Nimrod
this are two different options or i have to do one after other.
uttam
Two different options.
Nimrod