title: Core Data swift3 same primaryKey but different objectId in picker
body: <p>I'm an absolute newbie with Swift and Core Data.</p>
  
  <p>I created a two Entity learning app, nothing special.</p>
  
  <p>I'm stuck in finding why (AFAICT) my "Persona" picker objects in my "Medicina" Entity are different from the ones shown directly in the "Persona" Core Data table; since adding a <strong>predicate</strong> to filter the "Persona" Core Data table using the data obtained from the mentioned picker <strong>always return 0 elements</strong>.</p>
  
  <h1>Details:</h1>
  
  <p>The Personas Core Data Table shows all the entities already added to the app, with no problems and It's possible to edit them.</p>
  
  <p>When the following code in "PersonaTableViewController" gets executed:</p>
  
  <pre><code>...
  
  try self.fetchedResultsController.performFetch()
  
  ...
  </code></pre>
  
  <p>The logs show:</p>
  
  <pre><code>CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCREATEDAT, t0.ZFECHANACIMIENTO, t0.ZMODIFIEDAT, t0.ZNOMBRE, t0.ZPESO FROM ZPERSONA t0 ORDER BY t0.ZCREATEDAT
  CoreData: annotation: sql connection fetch time: 0.0006s
  CoreData: annotation: fetch using NSSQLiteStatement &lt;0x1c029abd0&gt; on entity 'Persona' with sql text 'SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCREATEDAT, t0.ZFECHANACIMIENTO, t0.ZMODIFIEDAT, t0.ZNOMBRE, t0.ZPESO FROM ZPERSONA t0 ORDER BY t0.ZCREATEDAT' returned 9 rows with values: (
      "&lt;Persona: 0x1c029a900&gt; (entity: Persona; id: 0xd000000000040004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p1&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029a950&gt; (entity: Persona; id: 0xd000000000080004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p2&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029b6c0&gt; (entity: Persona; id: 0xd0000000000c0004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p3&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029a810&gt; (entity: Persona; id: 0xd000000000100004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p4&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029a860&gt; (entity: Persona; id: 0xd000000000140004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p5&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029b940&gt; (entity: Persona; id: 0xd000000000180004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p6&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029a590&gt; (entity: Persona; id: 0xd0000000001c0004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p7&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029a770&gt; (entity: Persona; id: 0xd000000000200004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p8&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c029b5d0&gt; (entity: Persona; id: 0xd000000000240004 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p9&gt; ; data: &lt;fault&gt;)"
  )
  CoreData: annotation: total fetch execution time: 0.0062s for 9 rows.
  </code></pre>
  
  <p>Then, the user needs to select a "Persona" entity in the "Medicina" Entity. So, there is a Picker component.</p>
  
  <p>The piker is populated with this fragment of code:</p>
  
  <pre><code>func personaPickerInit(pPersonaPicker: UIPickerView) {
  
      personaPicker.delegate = self
  
      guard let managedObjectContext = managedObjectContext else { return }
  
      let personasFetch = NSFetchRequest&lt;NSFetchRequestResult&gt;(entityName: "Persona")
      let sort = NSSortDescriptor(key: "nombre", ascending: true)
      personasFetch.sortDescriptors = [sort]
  
      do {
          let personaPickerObjects = try managedObjectContext.fetch(personasFetch) as! [Persona]
  
  ...
  </code></pre>
  
  <p>On execution, it shows the following in the logs:</p>
  
  <pre><code>CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCREATEDAT, t0.ZFECHANACIMIENTO, t0.ZMODIFIEDAT, t0.ZNOMBRE, t0.ZPESO FROM ZPERSONA t0 ORDER BY t0.ZNOMBRE
  CoreData: annotation: sql connection fetch time: 0.0003s
  CoreData: annotation: fetch using NSSQLiteStatement &lt;0x1c4096c60&gt; on entity 'Persona' with sql text 'SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZCREATEDAT, t0.ZFECHANACIMIENTO, t0.ZMODIFIEDAT, t0.ZNOMBRE, t0.ZPESO FROM ZPERSONA t0 ORDER BY t0.ZNOMBRE' returned 9 rows with values: (
      "&lt;Persona: 0x1c4093f60&gt; (entity: Persona; id: 0xd000000000040002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p1&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4097070&gt; (entity: Persona; id: 0xd000000000140002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p5&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099a00&gt; (entity: Persona; id: 0xd000000000180002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p6&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099b90&gt; (entity: Persona; id: 0xd0000000001c0002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p7&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099be0&gt; (entity: Persona; id: 0xd000000000200002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p8&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099af0&gt; (entity: Persona; id: 0xd000000000240002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p9&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099c80&gt; (entity: Persona; id: 0xd000000000100002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p4&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099960&gt; (entity: Persona; id: 0xd000000000080002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p2&gt; ; data: &lt;fault&gt;)",
      "&lt;Persona: 0x1c4099820&gt; (entity: Persona; id: 0xd0000000000c0002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p3&gt; ; data: &lt;fault&gt;)"
  )
  CoreData: annotation: total fetch execution time: 0.0020s for 9 rows.
  </code></pre>
  
  <p>When It's time to let the user see/edit the "Persona" details, I add a predicate in the <code>PersonaTableViewController</code> so it should show only one "Persona".</p>
  
  <p>I tried passing around the whole objects in an array called <code>personasFiltradas</code> using the following predicate:</p>
  
  <pre><code>self.fetchedResultsController.fetchRequest.predicate =  NSPredicate(format: "self IN %@", self.personasFiltradas);
  </code></pre>
  
  <p>With the corresponding log:</p>
  
  <pre><code>CoreData: annotation: logically false fetch request &lt;NSFetchRequest: 0x1c40ce770&gt; (entity: Persona; predicate: (SELF IN {&lt;Persona: 0x1c02994b0&gt; (entity: Persona; id: 0xd000000000100002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p4&gt; ; data: {
      createdAt = "1509640324.844775";
      fechaNacimiento = 886399200;
      medicinas = "&lt;relationship fault: 0x1c423c640 'medicinas'&gt;";
      modifiedAt = 0;
      nombre = "ggjfghcb jggjfhh hgjfjdj hfghfhfj utility uutsyifgu uyffuftjg. I I iuuuhhu Hugh";
      peso = "207.8";
  })}); sortDescriptors: ((
      "(createdAt, ascending, compare:)"
  )); type: NSManagedObjectResultType; ) short circuits.
  CoreData: annotation: total fetch execution time: 0.0000s for 0 rows.
  </code></pre>
  
  <p>Also tried passing around the <code>objectID</code>in an array called <code>personasFiltradasIds</code> using the following predicate:</p>
  
  <pre><code>self.fetchedResultsController.fetchRequest.predicate =  NSPredicate(format: "Persona.objectID IN %@", self.personasFiltradasIds);
  </code></pre>
  
  <p>The corresponding log shows:</p>
  
  <pre><code>CoreData: annotation: logically false fetch request &lt;NSFetchRequest: 0x1c40cfea0&gt; (entity: Persona; predicate: (Persona.objectID IN {0xd000000000100002 &lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p4&gt;}); sortDescriptors: ((
      "(createdAt, ascending, compare:)"
  )); type: NSManagedObjectResultType; ) short circuits.
  CoreData: annotation: total fetch execution time: 0.0000s for 0 rows.
  </code></pre>
  
  <p>If you pay attention to both "log" entries shown before, You can see the same objects (paths like: <code>&lt;x-coredata://77904C2D-4B98-47DE-8A14-20A6F1CEB491/Persona/p1&gt;</code>) have different ObjectID's, so the grid is always empty since the ones in the table end with a "4" and the ones in the picker end with a "2". (In fact those "id's" keep changing. The problem is the ones on the picker are always different from the ones in the table) </p>
  
  <p>I'm not sure if my diagnose is correct, but that is what I can see.</p>
  
  <p>Any help finding why my code is not working would be greately appreciated</p>
  
  <hr>
  
  <h1>Edit 1</h1>
  
  <p>Here I add the model.</p>
  
  <p><a href="https://i.stack.imgur.com/cqL8R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cqL8R.png" alt="enter image description here"></a></p>