copying an sqlite file from one project to another - ios

Following this tutorial http://www.raywenderlich.com/12170/core-data-tutorial-how-to-preloadimport-existing-data-updated, I created an empty command line application using core data to seed a database which I subsequently moved (by taking the quizgeodata.sqlite file) over to an ios application I am building. The only other step the tutorial lists for making it work is to add this code to the persistantStoreCoordinator in app delegate
if (![[NSFileManager defaultManager] fileExistsAtPath:[storeURL path]]) {
NSURL *preloadURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"quizgeodata" ofType:#"sqlite"]];
NSError* err = nil;
if (![[NSFileManager defaultManager] copyItemAtURL:preloadURL toURL:storeURL error:&err]) {
NSLog(#"Oops, could copy preloaded data");
}
}
(Previous steps included taking the class files (that correspond to the entities) and the ...xcdatamodel.d file into the empty command line application to make sure that the schemas would be the same). When I run the code in the empty command line application, it shows the fetched data that I imported in the log statements, so I assume by copying the quizgeodata.sqlite back to the ios application and adding that one bit of code in the persistent store coordinator, then the following code (in viewDidLoad) should fetch the data from core data, but the log statements are showing that no data's been retrieved. The log of the error in the code below says 'null' (meaning no error I assume) and when I ask xCode to print the sql statements it shows this in the console
2014-04-17 16:11:57.477 qbgeo[767:a0b] CoreData: annotation: total fetch execution time: 0.0026s for 0 rows.
so obviously there's no data in the sqlite file that I copied over. Can you explain what I might need to do to get it working?
Please note that I ran Project > Clean several times so that is not the issue
from ViewDidLoad
id delegate = [[UIApplication sharedApplication] delegate];
self.managedObjectContext = [delegate managedObjectContext];
NSError *error;
if (![self.managedObjectContext save:&error]) {
NSLog(#"Whoops, couldn't save: %#", [error localizedDescription]);
}
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
entityForName:#"Sportsquiz" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSLog(#"error %#", [error description]);
NSArray *messedUpObjects = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (Sportsquiz *info in messedUpObjects) {
NSLog(#"correctAnswer %#", [info valueForKey:#"question"]);
NSLog(#"correctAnswer %#", [info valueForKey:#"correctAnswer"]);
}

Let's try:
The original project:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"TinMung.sqlite"];
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSMutableDictionary *pragmaOptions = [NSMutableDictionary dictionary];
/*ATTETION: disable WAL mode*/
[pragmaOptions setObject:#"DELETE" forKey:#"journal_mode"];
NSNumber *optionYes = [NSNumber numberWithBool:YES];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
pragmaOptions, NSSQLitePragmasOption,
optionYes,NSMigratePersistentStoresAutomaticallyOption ,nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
abort();
}
return _persistentStoreCoordinator;
}
Copy sqlite file to new project and fetch. I think it will work.

Related

iOS Core Data NSPersistentStoreCoordinator never opened database

I've got some weird problems with Core Data in my iOS which I cannot seem to reproduce, it just happens from time to time with some users that report it. The error I get from my iOS crash reports:
CoreData: -[NSPersistentStoreCoordinator _coordinator_you_never_successfully_opened_the_database_so_saving_back_to_it_is_kinda_hard:] + 56
Here is a screenshot (left out the product name):
The hard thing is that I don't get any search results on that error. Here is my (relevant) code:
saving:
-(void)save
{
if(!self.horecaMOC.hasChanges)return;
NSError *error;
[self.horecaMOC save:&error];
if(error)
{
NSLog(#"save error %#",error.localizedDescription);
}
}
MOC:
-(NSManagedObjectContext*)horecaMOC
{
if(!_horecaMOC)
{
NSPersistentStoreCoordinator *coordinator = self.horecaPSC;
if (coordinator != nil) {
_horecaMOC = [[NSManagedObjectContext alloc] init];
[_horecaMOC setPersistentStoreCoordinator:coordinator];
}
}
return _horecaMOC;
}
PSC:
-(NSPersistentStoreCoordinator*)horecaPSC
{
if(!_horecaPSC)
{
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"horeca.sqlite"];
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
NSError *error = nil;
_horecaPSC = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:self.horecaMOM];
if (![_horecaPSC addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
return _horecaPSC;
}
MOM:
-(NSManagedObjectModel*)horecaMOM
{
if(!_horecaMOM)
{
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:#"poi" withExtension:#"momd"];
_horecaMOM = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
}
return _horecaMOM;
}
It seems like the setup is OK here, because 99% of the time it works, but sometimes I get that error that I did not open the database. Since I can't debug it's hard to figure out what's the cause. Might the PSC nil? And why would that then be? Also, I know that a MOC should be bound to 1 thread only, and since I can't get it to crash I don't think there could be an issue regarding this?
Thanks for any advice!

iOS App mistakenly creating multiple sqlite files for a test case, thus leading to repetitive file downloads

I have implemented core data in my ios app. Now when downloading and saving files to database, if I quit the process in between and then start again it creates new sqlite file everytime. This leads to app taking files from database for first few files, while storing the later files in a seperate database which it doesn't access later. This eventually leads to downloading of later files everytime and creating a new database for it. I am pretty confused on how to fix this. Following is my core data code from AppDelegate class, hoever, I need to run the operation continued in background also , so no fixing there:
#pragma mark - Core Data stack
#synthesize managedObjectContext = _managedObjectContext;
#synthesize managedObjectModel = _managedObjectModel;
#synthesize persistentStoreCoordinator = _persistentStoreCoordinator;
- (NSURL *)applicationDocumentsDirectory {
// The directory the application uses to store the Core Data store file. This code uses a directory named "acme.in.EcoGrid" in the application's documents directory.
return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}
- (NSManagedObjectModel *)managedObjectModel {
// The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.
if (_managedObjectModel != nil) {
return _managedObjectModel;
}
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:#"EcoGrid" withExtension:#"momd"];
_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return _managedObjectModel;
}
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
// Create the coordinator and store
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"EcoGrid.sqlite"];
NSError *error = nil;
NSString *failureReason = #"There was an error creating or loading the application's saved data.";
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
// Report any error we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = #"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:#"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
// Replace this 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.
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
return _persistentStoreCoordinator;
}
- (NSManagedObjectContext *)managedObjectContext {
// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
if (_managedObjectContext != nil) {
return _managedObjectContext;
}
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (!coordinator) {
return nil;
}
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];
return _managedObjectContext;
}
#pragma mark - Core Data Saving support
- (void)saveContext {
NSManagedObjectContext *managedObjectContext = self.managedObjectContext;
if (managedObjectContext != nil) {
NSError *error = nil;
if ([managedObjectContext hasChanges] && ![managedObjectContext save:&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.
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
}
-(void)deleteAndRecreateStore{
NSPersistentStore * store = [[self.persistentStoreCoordinator persistentStores] lastObject];
NSError * error;
[self.persistentStoreCoordinator removePersistentStore:store error:&error];
[[NSFileManager defaultManager] removeItemAtURL:[store URL] error:&error];
_managedObjectContext = nil;
_persistentStoreCoordinator = nil;
[self managedObjectContext];
}
Any help here is highly appreciated!
Looks like the problem is resolved by placing an if condition in persistentStore Coordinator method like this:-
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
// Create the coordinator and store
NSFileManager *filemgr = [NSFileManager defaultManager];
if ([filemgr fileExistsAtPath: [[[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"EcoGrid.sqlite"] absoluteString] ] == NO) {
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"EcoGrid.sqlite"];
NSError *error = nil;
NSString *failureReason = #"There was an error creating or loading the application's saved data.";
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
// Report any error we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = #"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:#"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
// Replace this 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.
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
else{
}
return _persistentStoreCoordinator;
}

Close and Re-open or refresh downloaded database

I'm looking for a easy solution to close my database et re-open it.
My App is using an database (CoreData) with formulas, then, when new formulas are available, my App, will download the full database and replace the actual.
This part is working well. But, once downloaded, I'd like to refresh a TableView with the new Database. I checked on the website and internet but, I didn't find answer.
Seems this is linked to the Persistent but not sure.
So I tried to reset my context but, my TableView is only updated once App been closed and re opened.
So, I'd like to know if you have time to give me an example of how to refresh or even close and re open the database.
Thanks in advance for your support.
NSData *fetchedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:#"u189496386:xxxxx#xxxxx.com:21/DataBase.sqlite"]];
NSUInteger length = [fetchedData length];
ProgressDownload.progress = 0.5f;
if(length < 1)
{
ContactServer.text = #"Error downloading DataBase or Network access, please check your connection";
}
else
{
ContactServer.text = #"Server contacted, download in progress";
}
NSString *documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *filePath = [documentsPath stringByAppendingPathComponent:#"DataBase.sqlite"];
testEcriture = [fetchedData writeToFile:filePath atomically:YES];
if(testEcriture == YES)
{
ContactServer.text = #"Database updated";
ProgressDownload.progress = 1.0f;
}
Then, once back to the first view, the )viewDidLoad is executed, but it seems the content didn't changed.
mesProduits = [[NSMutableArray alloc] init];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:#"Projector" inManagedObjectContext:context];
NSFetchRequest *frequest = [[NSFetchRequest alloc] init];
[frequest setEntity:entityDesc];
NSSortDescriptor *sortDescription = [[NSSortDescriptor alloc] initWithKey:#"model" ascending:YES];
[frequest setSortDescriptors:#[sortDescription]];
NSError *error;
NSArray *matchingData = [context executeFetchRequest:frequest error:&error];
Your managed object context has a property, persistentStoreCoordinator, which provides a reference to the persistent store coordinator underpinning the database. The PSC accesses the persistent store to read and write the data.
So, to replace the database you would do something along these lines:
NSManagedObjectContext *context = self.context;
NSError *error = nil;
// Save the context before doing anything else.
if (![context save:&error]) {
NSLog(#"Error saving context: %#, %#", error, [error userInfo]);
abort();
}
// Get URL to the current database...
NSPersistentStoreCoordinator *psc = context.persistentStoreCoordinator;
NSPersistentStore *currentStore = psc.persistentStores[0];
NSURL *currentURL = currentStore.URL;
// Get URL to the new database...
NSURL *appDocs = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *newDatabaseURL = [appDocs URLByAppendingPathComponent:#"DataBase.sqlite"];
// Disconnect from the current database...
if (![psc removePersistentStore:currentStore error:&error]) {
NSLog(#"Error removing store: %#, %#", error, [error userInfo]);
abort();
}
// Replace the old database with the new, keeping a backup copy...
if (![[NSFileManager defaultManager] replaceItemAtURL:currentURL withItemAtURL:newDatabaseURL backupItemName:#"DataBase.backup" options:(NSFileManagerItemReplacementUsingNewMetadataOnly | NSFileManagerItemReplacementWithoutDeletingBackupItem) resultingItemURL:nil error:&error]) {
NSLog(#"Error replacing the store: %#, %#", error, [error userInfo]);
abort();
}
// Open the new database...
NSString *failureReason = #"There was an error creating or loading the application's saved data.";
if (![psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:currentURL options:nil error:&error]) {
// Report any error we got.
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
dict[NSLocalizedDescriptionKey] = #"Failed to initialize the application's saved data";
dict[NSLocalizedFailureReasonErrorKey] = failureReason;
dict[NSUnderlyingErrorKey] = error;
error = [NSError errorWithDomain:#"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
The various error cases should be properly handled, I've just logged and aborted for demonstration purposes. Be aware that your new database must match the schema for the existing database, or you will get an error. And obviously anything previously written to your old database is lost.

Slow Core-Data fetch operation, with readonly sqlite database

Core Data fetch operation is slow with a Read-only sqlite database. Can I improve its performance?
Background: I have a core-data model with 2 configurations. One for the default application store, and another for seed-data (SeedData.sqlite). The SeedData.sqlite is placed inside the application bundle, and is setup as a Read-only store. The SeedData.sqlite contains approximately 6500 records.
This is how I setup 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 {
NSLog(#"%s", __FUNCTION__);
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
// Attempt to load the persistent store
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
// Create the default/ user model persistent store
{
NSString *storeFileName = [JTCoreDataManager defaultStoreName];
NSString *configuration = #"AppName";
NSURL *storeURL = [[self applicationLocalDatabaseDirectory] URLByAppendingPathComponent:storeFileName];
// Define the Core Data version migration options
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:configuration
URL:storeURL
options:options
error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
abort();
}
}
// Create the seed data persistent store
{
NSURL *seedDataURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:#"SeedData" ofType:#"sqlite"]];
NSString *configuration = #"SeedData";
// Define the Core Data version migration options
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
[NSNumber numberWithBool:YES], NSReadOnlyPersistentStoreOption,
nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:configuration
URL:seedDataURL
options:options
error:&error]) {
NSLog(#"Unresolved error %#, %#", error, [error userInfo]); abort();
abort();
}
}
return _persistentStoreCoordinator;
}
The fetched results controller is setup like this:
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:#"Seed"];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"title" ascending:YES];
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"magicOn == %#", [NSNumber numberWithBool:YES]];
[fetchRequest setPredicate:predicate];
[fetchRequest setSortDescriptors:#[sortDescriptor]];
[fetchRequest setFetchBatchSize:20];
NSFetchedResultsController *fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest
managedObjectContext:self.managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
NSError *error;
BOOL success = [fetchedResultsController performFetch:&error];
if (!success) {
NSLog(#"%#", [error localizedDescription]);
}

Determining when there are new versions in core data model

Short question:
I want to run a certain code in my app only if my Core Data model has changed (new entities, new properties, etc). How can I determine if the model has changed or not?
Just some pseudo-code:
if (current_model_version != previous_model_version) {
//do some code
} else {
// do some other code
}
I'm guessing I might use versionHashes to do this, or isConfiguration:compatibleWithStoreMetadata:, but I'm not certain how.
Some editing for clarity: 'current' as in 'now' and 'previous' as in 'last time app was launched.'
The answer seems to be isConfiguration:compatibleWithStoreMedia:.
I found some useful information here:
http://mipostel.com/index.php/home/70-core-data-migration-standard-migration-part-2
I set it up this way:
- (BOOL)modelChanged
{
NSError *error;
NSURL * sourceURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:#"db.sqlite"];
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:sourceURL error:&error];
BOOL isCompatible = [[self managedObjectModel] isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
return isCompatible;
}
'self' is my shared data store, not that it necessarily has to go there.
deanWombourne points out that what this really does is determine whether or not the data can be automatically migrated, so it's not exactly the solution to the problem I posed. It does serve my needs in this case.
This is replacement code for - (NSPersistentStoreCoordinator *)persistentStoreCoordinator that you get if you tick the Core Data box when setting up a new project in XCode.
It attempts to open the existing sqlite file (using lightweight migration if necessary). If that fails, it deletes and re-creates the store.
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSError *error = nil;
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.storeURL options:options error:&error])
{
NSLog(#"Couldn't open the store. error %#, %#", error, [error userInfo]);
[self deleteSqliteFilesForStore:self.storeURL];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:self.storeURL options:options error:&error])
{
NSLog(#"Unresolved error %#, %#", error, [error userInfo]);
// or [NSException raise ...]
}
else
{
NSLog(#"Store deleted and recreated");
// TEST DATA RE-INITIALIZATION CODE GOES HERE
}
}
else
{
NSLog(#"Existing Store opened successfully");
}
return _persistentStoreCoordinator;
}
- (void)deleteSqliteFilesForStore:(NSURL *)storeURL
{
NSURL *baseURL = [storeURL URLByDeletingPathExtension];
// Delete the associated files as well as the sqlite file
for (NSString *pathExtension in #[#"sqlite",#"sqlite-shm",#"sqlite-wal"])
{
NSURL *componentURL = [baseURL URLByAppendingPathExtension:pathExtension];
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[componentURL path]];
if(fileExists)
{
[[NSFileManager defaultManager] removeItemAtPath:[componentURL path] error:nil];
}
}
}

Resources