Reputation: 4287
I figured you can create new entities (in swift 3
) like this:
let person = Person(context: persistentContainer.viewContext)
person.name = "Some Name"
This seems to be it. It saves the new person permanently (I think so, at least).
Why don't you need to call saveContext()
of AppDelegate. swift (or persistentContainer.viewContext.save()
which is basically the same, right?)?
Every time you change some entity
, you need to save it. Why isn't this the case when creating new entities
?
Thanks in Advance !!!
Upvotes: 0
Views: 348
Reputation: 2786
for your anser you have to understand the Core Data stack
Changes that you make to your managed objects are not committed to the parent store until you save the context.
Upvotes: 1
Reputation: 7373
According to your comments on your question, you ARE calling saveContext()
.
Go into your AppDelegate
and check out applicationWillTerminate
, saveContext()
is called there.
In short, if you want to persist the data then yes, you need to call saveContext()
Upvotes: 1