iOS:Swift:CoreData: Values are not stored using PrivateManagedObjectContext iOS:Swift:CoreData: Values are not stored using PrivateManagedObjectContext swift swift

iOS:Swift:CoreData: Values are not stored using PrivateManagedObjectContext


Saving a child context just pushes those changes up to the parent context. Unless you're also saving the parent context (which pushes changes to the persistent store) then your changes will not be written to disk.

From the NSManagedObjectContext class reference:

When you save changes in a context, the changes are only committed “one store up.” If you save a child context, changes are pushed to its parent. Changes are not saved to the persistent store until the root context is saved. (A root managed object context is one whose parent context is nil.)

If you're new to core data, I'd suggest not worrying about concurrency and multiple contexts unless you actually have a problem that requires that to solve it. Unless you're dealing with thousands of records or you're interested in creating editing contexts for reversible changes, a single main thread context will do everything you need.