CoreData unique constraints: how to get field name on which constraint checking fails
<p>I have a simple table "Person" with two fields:
identity => String
name => String
This table have unique separated constraints: identity and name (not identity + name)</p>

<p>I try to insert into this table same data several times:</p>

<pre><code>let names = ["Name1", "Name2", "Name3"]
for i in 0..&lt;3 {
    let p = Person() //NSManagedObject sublass
    p.identity = "1111"
    p.name = names[i]
    do { try p.managedObjectContext!.save() }
    catch let e as NSError { 
        if e.code == NSCocoaError.ManagedObjectConstraintMergeError.rawValue {
            print(e.userInfo["conflictList"]![0]!) 
        }
    }
}
</code></pre>

<p>I have in log:</p>

<blockquote>
  <p>NSConstraintConflict (0x7ff12b84f600) for constraint (
      identity
  ): database:  (entity: Person; id: 0xd000000000040000  ; data: ), conflictedObjects: (
      " (entity: Person; id: 0xd000000000140000  ; data: {\n    identity = 1111;\n    name = Name1;\n})"
  )</p>
</blockquote>

<p>How can I get field name on which constraint failes from userInfo  NSConstraintConflict (0x7ff12b84f600) for constraint ( <strong>identity</strong> ) ? Because in future I want to show messages with text like "Unique constraint check failed for field "identity" and "Unique constraint check failed for field "name" but while I cann't get field name from error it is not clear on which field check failed</p>

<p>Thank you!</p>