|
I am trying to understand Core Data and constraints. I am trying to establish a model with 2 entities: a Wizard which can have multiple spells, and a Spell which can be owned by multiple Wizards. Each Wizard has has only one attribute, name, and each Spell has only one attribute, name. I do not want duplicates to be saved so I set contraints on both name attributes in both Spell and Wizard. I think the appropriate relationship is one Wizard to many Spells My data model is called Wizards.xcdatamodeld I am using Paul's instructions to manually unwrap the optionals and sets from the Core Data classes. The app runs and loads and displays the appropriate example data. I repeatedly get this error thrown with saving that I cannot understand. "Thread 1: "This NSPersistentStoreCoordinator has no persistent stores (schema mismatch or migration failure). It cannot perform a save operation." I searched but can't find an answer, can anyone help? I am attaching my code
|
|
I assume that the code is in separate files, because there appear to be a lot of repeated import commands. When you create your CoreData you need to version your models especially if you have changed your models alot. Coredata uses a SQLite DB, and Xcode / SwiftUI uses a lightweight migration every time you do a small change to models. Essentially, it automatically handles how to migrate your initial model definition (first schema) to the new / changed one (second schema), but only for small and simple changes. Do too many changes, or something complicated, it cannot automatically match the schemas and cannot perform the migration of the model and data from the old version to the new one. In this case you would have to write the merge functionality yourself, and that is a whole lot of other work. No persistent stores schema mismatch I think that if you delete the application, and any associated data, it should delete the SQLite DB as well, and you can start again. |
|
Thanks you for the help. All the code files were in separate files. I erased all contents and settings in the simulator and the program ran again without the error. Is there an up to date tutorial for me to read on how to modify Core Date data models on existing projects? It was hard to find a good one on HWS+. My goal of taking the 100 Days of Swift UI is to create an app to manage books, and gradually add features over time. I am sure I will need to use Core Data and CloudKit eventually. I tried to find an understandable up to date tutorial and was not very successful. |
|
Core Data is one of the more common key topics to get familar with. Paul does an excellent explanation on how he views and uses it. It does require a more in-depth look to really start to understand the intricacies and behind-the-scenes methods used by SwiftUI to manage Core Data. For reference I use the book If you search the internet, you will be able to find other resources that cover Core Data. Paul has written about how to be a developer, where he has also listed some other useful sources of information and learning. How to be an iOS developer in 2021 |
SAVE 50% All our books and bundles are half price for Black Friday, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.