In my app I sometimes need to rebuild and repopulate database file. SQLite databse is created and managed by CoreData stack.
What I\'m trying to do is drop the file
The Core Data stack does not like you removing the file under it. If you are wanting to delete the file you should tear down the stack, delete the file and then reconstruct the stack. That will eliminate the issue.
Part of the problem is that the stack keeps a cache of the data that is in the file. When you remove the file you don't have a way to clear that cache and you are then putting Core Data into an unknown and unstable state.
You can try telling the NSPersistentStoreCoordinator
you are removing the file with a call to -removePersistentStore:error:
and then adding the new store with a call to -addPersistentStoreWithType:configuration:URL:options:error:
. I am doing that currently in ZSync and it works just fine.