---
title: save()
framework: coredata
role: symbol
role_heading: Instance Method
path: coredata/nsmanagedobjectcontext/save()
---

# save()

Attempts to commit unsaved changes to registered objects to the context’s parent store.

## Declaration

```swift
func save() throws
```

## Mentioned in

Accessing data when the store changes

## Discussion

Discussion If there were multiple errors (for example several edited objects had validation failures) the description of NSError returned indicates that there were multiple errors, and its userInfo dictionary contains the key NSDetailedErrors. The value associated with the NSDetailedErrors key is an array that contains the individual NSError objects. If a context’s parent store is a persistent store coordinator, then changes are committed to the external store. If a context’s parent store is another managed object context, then save() only updates managed objects in that parent store. To commit changes to the external store, you must save changes in the chain of contexts up to and including the context whose parent is the persistent store coordinator. important: Always verify that the context has uncommitted changes (using the hasChanges property) before invoking the save: method. Otherwise, Core Data may perform unnecessary work.

## See Also

### Managing unsaved and uncommitted changes

- [hasChanges](coredata/nsmanagedobjectcontext/haschanges.md)
