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

# NSConstraintConflict

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

```
class NSConstraintConflict
```

## Overview

A constraint conflict occurs when your data model is using unique constraints and one or more managed objects are violating that constraint.

When this error occurs, the error instance can be interrogated to determine which instance of [`NSManagedObject`](/documentation/CoreData/NSManagedObject) is violating the constraint and which property on the [`NSManagedObject`](/documentation/CoreData/NSManagedObject) instance is in violation.

## Topics

### Initializing a Conflict

[`-  initWithConstraint:databaseObject:databaseSnapshot:conflictingObjects:conflictingSnapshots:`](/documentation/CoreData/NSConstraintConflict/init(constraint:database:databaseSnapshot:conflicting:conflictingSnapshots:))

Initializes a constraint conflict.

### Inspecting a Conflict

[`conflictingObjects`](/documentation/CoreData/NSConstraintConflict/conflictingObjects)

The managed objects that are in conflict.

[`conflictingSnapshots`](/documentation/CoreData/NSConstraintConflict/conflictingSnapshots)

The original property values of objects in violation of the constraint.

[`constraint`](/documentation/CoreData/NSConstraintConflict/constraint)

The constraint that has been violated.

[`constraintValues`](/documentation/CoreData/NSConstraintConflict/constraintValues)

The values that the conflicting objects had when the conflict was created.

[`databaseObject`](/documentation/CoreData/NSConstraintConflict/databaseObject)

The object whose database row is using constraint values.

[`databaseSnapshot`](/documentation/CoreData/NSConstraintConflict/databaseSnapshot)

The values currently stored in the database.

## Relationships

### Conforms To

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

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

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

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

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

[`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)