Quantm Quantm - 1 month ago 4x
Swift Question

CoreData - creating new entity - Why don't you need to save this?

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
of AppDelegate. swift (or
which is basically the same, right?)?

Every time you change some
, you need to save it. Why isn't this the case when creating new

Thanks in Advance !!!


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()