Class

NSMergePolicy

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

Declaration

class NSMergePolicy : NSObject

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.

Topics

Getting a Merge Policy

init(merge: NSMergePolicyType)

Returns a merge policy initialized with a given policy type.

Resolving a Conflict

func resolve(mergeConflicts: [Any])

Resolves the conflicts in a given list.

func resolve(constraintConflicts: [NSConstraintConflict])

Resolves the conflicts in a given list.

Defining Merge Policies

class var error: NSMergePolicy

Default policy for all managed object contexts.

class var mergeByPropertyObjectTrump: NSMergePolicy

A policy that merges conflicts between the persistent store's version of the object and the current in-memory version by individual property, with the external changes trumping in-memory changes.

class var mergeByPropertyStoreTrump: NSMergePolicy

A policy that merges conflicts between the persistent store's version of the object and the current in-memory version by individual property, with the in-memory changes trumping external changes.

class var overwrite: NSMergePolicy

A policy that merges conflicts between the persistent store's version of the object and the current in-memory version by pushing the entire in-memory object to the persistent store.

class var rollback: NSMergePolicy

A policy that merges conflicts between the persistent store's version of the object and the current in-memory version by discarding all state for the changed objects in conflict.

Merge Policies

Define standard ways to handle conflicts during a save operation.

Relationships

Inherits From

Conforms To

See Also

Conflict Management

class NSConstraintConflict

An encapsulation of conflicts that occur during an attempt to save a managed object.

class NSMergeConflict

An encapsulation of conflicts that occur during an attempt to save changes in a managed object context.

class NSQueryGenerationToken

A token that indicates which generation of the persistent store is being accessed.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software