In objective while using the the coredata concept we need to create the splite as persistent store or it will created automatically ?
+2
A:
When creating a new iPhone app project in Xcode, most of the templates allow the "Use Core Data for storage" option. When this is checked, the application delegate will include some boilerplate Core Data code including this block that opens and/or creates the persistent store:
/**
Returns the persistent store coordinator for the application.
If the coordinator doesn't already exist, it is created and the application's store added to it.
*/
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
if (persistentStoreCoordinator != nil) {
return persistentStoreCoordinator;
}
NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"App.sqlite"]];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) {
/*
Replace this implementation with code to handle the error appropriately.
abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. If it is not possible to recover from the error, display an alert panel that instructs the user to quit the application by pressing the Home button.
Typical reasons for an error here include:
* The persistent store is not accessible
* The schema for the persistent store is incompatible with current managed object model
Check the error message to determine what the actual problem was.
*/
//NSLog(@"Error with persistent store %@, %@", error, [error userInfo]);
NSLog(@"Error with persistent store (did the data model change?)");
abort();
}
return persistentStoreCoordinator;
}
gerry3
2010-01-08 06:37:15
you mean it will create sqlite as persistent store automatically.pls reply soon.
uttam
2010-01-08 06:46:11
Yes, this code does that. Please ACCEPT answers to your questions if the answers helped.
gerry3
2010-01-08 06:56:31
If i want to add data in it then how i can add ?
uttam
2010-01-08 08:37:53
You can add data to it just like any other data store, Core Data abstracts that away for you.See the Core Data Programming Guide for a great walkthrough on using Core Data, regardless of data store: http://developer.apple.com/Mac/library/documentation/Cocoa/Conceptual/CoreData/cdProgrammingGuide.html
ctshryock
2010-01-08 14:31:09