Agenda
Prehistory. (Constraints, background context, network and JSON decoding)
What is that a merge policy?
Base merge policies
How conflicts merged for different policies
Custom merge policy
you use to resolve conflicts between the persistent store and in-memory versions of managed objects. 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.
list { guard let databaseObject = conflict.databaseObject else { try super.resolve(constraintConflicts: list) return } let allKeys = databaseObject.entity.attributesByName.keys for conflictObject in conflict.conflictingObjects { let changedKeys = conflictObject.changedValues().keys let keys = allKeys.filter { !changedKeys.contains($0) } for key in keys { let value = databaseObject.value(forKey: key) conflictObject.setValue(value, forKey: key) } } } try super.resolve(constraintConflicts: list) }