My app is setup so that when it's first used, it downloads the required data from a web based xml feed.
The user also has the option to periodically refresh the data via a setting.
When they do this, I want to delete the existing database and then recreate it via the code I use for the first load.
I read that simply deleting the database is not the correct way to do this so I'm using the following to destroy the data before loading the new dataset.
- (void)resetApplicationModel {
NSURL *_storeURL = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: DBSTORE]];
NSPersistentStore *_store = [persistentStoreCoordinator persistentStoreForURL:_storeURL];
[persistentStoreCoordinator removePersistentStore:_store error:nil];
[[NSFileManager defaultManager] removeItemAtPath:_storeURL.path error:nil];
[persistentStoreCoordinator release], persistentStoreCoordinator = nil;
}
However this doesn't work, when performing a data refresh, it downloads the data but can't save it to the database and generates the following error in the console;
This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.
What's the "correct" way to refresh a database?