Will Core Data create a persistent storage file for me?

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.

+4
source share
3 answers

Yes, Core Data will create SQLite db immediately after the first launch of your application in your application.

+7
source

Yes. Core Data stack code containing Apple templates will create a database file if it does not already exist.

+2
source

Yes, this method adds a new persistent store of a certain type to a given location and returns a new store. Here is the documentation .

+1
source

Source: https://habr.com/ru/post/1300816/


All Articles