Adding new entity to core data model
So I followed an online tutorial rather than reading Apple’s documentation on it, what I did was, I added an entity to my core data model and wrote the logic to store data and it was all working! So now my app could store and retrieve data from a persistent data source without the storage limitation imposed by WebSql in a webView. It was all going great and thanks to Core Data both my app and I were in a land of blue skies and sunshine 🙂 Now that I had something that saved and retrieved with Core Data, I felt I should refine my solution and actually add all the entities that my app needs. So I added a few entities to my data model and re-deployed my app to the device and BANG!!!Until…a problem surfaced
The app crashed and I was no longer in the land of blue skies and sunshine. Why? In a nutshell, I needed to pay attention to what is described in Core Data Model Versioning and Data Migration. The solution is knowing all about what version of your Core Data model is your app dealing with. Or more like what your app knows it’s dealing with. Say you deploy version one of your app with entities Person and Vehicle, and then you add another entity called Animal and re-deploy your app to a device it will crash. Since the app is not expecting to find an Animal i.e. Animal entity. At this point if your delete I have written a more detailed post on the solution to this problem and you can see it here https://mydaytodo.com/core-data-migration-in-ios-app-swift/
If you find any of my posts useful and want to support me, you can buy me a coffee 🙂
https://www.buymeacoffee.com/bhumansoni
Or you can buying or even try one of my apps on the App Store.
https://mydaytodo.com/apps/
Also, if you can leave a review on the App Store or Google Play Store, that would help too.
0 Comments