Please tell me: if I use Core Data in my application for iPhone, I have basically two files. The file is mydatamodel.xcdatamodel and then I need the .sqlite file. Apple provides this piece of code:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSString *appDirPath = [self applicationDocumentsDirectory]; NSString *storeFileName = @"mystore.sqlite"; NSURL *storeUrl = [NSURL fileURLWithPath:[appDirPath stringByAppendingPathComponent:storeFileName]]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]) { NSLog(@"Error: %@, %@", error, [error userInfo]); abort(); } return persistentStoreCoordinator; }
Will this file be created if it is no longer available?
[persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:nil error:&error]
My application does not need the source data, because it will load it when the user starts the application.
source share