Persisting data and reacting to data changes
The first step to implement data persistence for your app is to make sure that you can store data in the database. You have defined the models that you want to store in your database, so the next step is to actually store your models. Once you have implemented a rough version of your data persistence, you will refine the code to make it more reusable. The final step will be to read data from Core Data and dynamically respond to changes in the database.
Understanding data persistence
Whenever you want to persist a model with Core Data, you must insert a new NSManagedObject
into NSManagedObjectContext
. Doing this does not immediately persist the model. It merely stages the object for persistence in the current NSManagedObjectContext
. If you don't properly manage your managed objects and contexts, this is a potential source of bugs. For example, not persisting your managed objects results in the loss of your data once you...