<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSManagedObjectContext/refresh(_:mergeChanges:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSManagedObjectContext(im)refreshObject:mergeChanges:"
  },
  "title" : "refresh(_:mergeChanges:)"
}
-->

# refresh(_:mergeChanges:)

Updates the persistent properties of a managed object to use the latest values from the persistent store.

```
func refresh(_ object: NSManagedObject, mergeChanges flag: Bool)
```

## Parameters

`object`

A managed object.

`flag`

A Boolean value.

    If     `flag`     is     <doc://com.apple.documentation/documentation/Swift/false>    , the context discards pending changes and the managed object becomes a fault. Upon next access, the context reloads the object’s values from the persistent store or last cached state.

    If     `flag`     is     <doc://com.apple.documentation/documentation/Swift/true>    , the context reloads the object’s property values from the store or the cache. Then the context applies local changes over the newly loaded values. Merging the local values into     `object`     always succeeds, and never results in a merge conflict.

## Discussion

If you call this method before the [`stalenessInterval`](/documentation/CoreData/NSManagedObjectContext/stalenessInterval) expires, the context reloads the data from the cache instead of fetching from the store. If `flag` is <doc://com.apple.documentation/documentation/Swift/true>, this method doesn’t affect any transient properties. If `flag` is <doc://com.apple.documentation/documentation/Swift/false>, the object disposes the value of transient properties.

You typically use this method to ensure data freshness if multiple managed object contexts share a single persistent store. You can use this method to resolve an optimistic locking failure when attempting to save.

Turning `object` into a fault by setting `flag` to <doc://com.apple.documentation/documentation/Swift/false> breaks strong references to related managed objects. You can use this method to release a portion of your object graph if you want to constrain memory usage.

## See Also

[`stalenessInterval`](/documentation/CoreData/NSManagedObjectContext/stalenessInterval)

The maximum length of time that may have elapsed since the store previously fetched data before fulfilling a fault issues a new fetch.

[`reset()`](/documentation/CoreData/NSManagedObjectContext/reset())

Returns the context to its base state.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)