I'm developing my own app and I have a problem with core data: I submitted my first app at the AppStore and for the next release, I have been doing changes in the Model (new entities has been added and few attributes from existing entities has been removed, added or updated). The mistake that I've done is do not create a new Model Version, I just have made the changes. Now, when I'm using the first version of the app and I change to the second, the app crashes because the Core Data Model has changed. I can't do any migration because the model is not versioned, so I don't have any previous version.
My idea is, when the app is runned for the first time, delete the data model let the app to create it again (there's no problem with data losing).
I have seen many ideas: Stack Overflow 1 Stack Overflow 2
but don't work, because they can't find my file, that's my code:
let documentsDirectory = URL(string: applicationDirectoryPath())! as NSURL
// I've tried many names as: Model.sqlite, Database.sqlite, database.sqlite
let storeURL = documentsDirectory.appendingPathComponent("model.sqlite")
do
{
try FileManager.default.removeItem(at: storeURL!)
} catch
{
print("Problem deleting core data")
}
How can I find the name of the file to put to this function
appendingPathComponent("I don't know the name of the file")
How can I do coda that? Any other idea?
Thanks for all!