<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.7.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreData",
  "identifier" : "/documentation/CoreData/NSMergePolicy",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Data"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMergePolicy"
  },
  "title" : "NSMergePolicy"
}
-->

# NSMergePolicy

A policy object that you use to resolve conflicts between the persistent store and in-memory versions of managed objects.

```
class NSMergePolicy
```

## Overview

A conflict is a mismatch between state held at two different layers in the Core Data stack. A conflict can arise when you save a managed object context and you have stale data at another layer. There are two places in which a conflict may occur:

- Between the managed object context layer and its in-memory cached state at the persistent store coordinator layer.
- Between the cached state at the persistent store coordinator and the external store (file, database, and so forth).

Conflicts are represented by instances of [`NSMergeConflict`](/documentation/CoreData/NSMergeConflict).

## Topics

### Getting a Merge Policy

[`-  initWithMergeType:`](/documentation/CoreData/NSMergePolicy/init(merge:))

Returns a merge policy initialized with a given policy type.

[`mergeType`](/documentation/CoreData/NSMergePolicy/mergeType)

The merge type.

### Resolving a Conflict

[`-  resolveConflicts:error:`](/documentation/CoreData/NSMergePolicy/resolve(mergeConflicts:))

Resolves the conflicts in a given list.

[`-  resolveConstraintConflicts:error:`](/documentation/CoreData/NSMergePolicy/resolve(constraintConflicts:))

Resolves the conflicts in a given list.

[`-  resolveOptimisticLockingVersionConflicts:error:`](/documentation/CoreData/NSMergePolicy/resolve(optimisticLockingConflicts:))

Resolves the conflicts in a given list.

### Defining Merge Policies

[`errorMergePolicy`](/documentation/CoreData/NSMergePolicy/error)

The default merge policy for all managed object contexts.

[`mergeByPropertyStoreTrumpMergePolicy`](/documentation/CoreData/NSMergePolicy/mergeByPropertyStoreTrump)

A property-based merge policy that applies external changes.

[`mergeByPropertyObjectTrumpMergePolicy`](/documentation/CoreData/NSMergePolicy/mergeByPropertyObjectTrump)

A property-based merge policy that applies in-memory changes.

[`overwriteMergePolicy`](/documentation/CoreData/NSMergePolicy/overwrite)

A merge policy that overwrites the entire stored object.

[`rollbackMergePolicy`](/documentation/CoreData/NSMergePolicy/rollback)

A merge policy that discards unsaved changes.

[Merge Policies](/documentation/CoreData/merge-policies)

Define standard ways to handle conflicts during a save operation.

## Relationships

### Conforms To

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`Hashable`](/documentation/Swift/Hashable)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)