gurehbgui
gurehbgui

Reputation: 14674

Do I have to save() my NSManagedObjectContext?

I'm quite new to iOS development and have the following question:

I'm using CoreData and I add a Element like this:

NSEntityDescription.insertNewObjectForEntityForName("Foo", inManagedObjectContext: moc) as! Foo

After restarting my App, it's still there. The question is:

When I should use the NSManagedObjectContext.save() function?

Upvotes: 1

Views: 79

Answers (1)

Abizern
Abizern

Reputation: 150575

You call save when you want to persist your changes to the disk.

Your method inserts a new object into the managedObjectContext. But the managedObjectContext is really just a temporary place to put things. When you create an object in a context, that doesn't automatically persist those changes to the Persistent Store until you call save on it.

Upvotes: 1

Related Questions