2

I have these permanent object ids that I got by fetching the same object in different contexts:

<x-coredata://F1697911-CD8A-4D63-B40F-AB0CA020C873/Facility/p1>
<x-coredata://F1697911-CD8A-4D63-B40F-AB0CA020C873/Facility/p2>

The GUID part F1697911-CD8A-4D63-B40F-AB0CA020C873is the same.
The entity part is the same.

What is p1 and p2 and why are they different?

my expectation is that the objects they represent should be the same.. I use them across different managed object contexts, but from what I understand the object id should be the same.

thanks.

Zsolt
  • 3,648
  • 3
  • 32
  • 47
  • good resource https://stackoverflow.com/a/12218565/429763 – Zsolt Dec 13 '18 at 10:08
  • Are this strings just description log out of some objects in console? – kirander Dec 13 '18 at 12:05
  • yes, only printouts on the console. but note p1 vs p2 – Zsolt Dec 13 '18 at 13:05
  • If this is just because you're interested in knowing how it works, that's cool. If you are writing (or planning to write) code that depends on this format, you're almost certainly making Core Data more complex than it needs to be, or making invalid assumptions. – Tom Harrington Dec 13 '18 at 18:34

1 Answers1

0

The p identifies the objectID as persistent, associated to its MOC. It is part of the whole URI.

Temporary URIs look different, e.g.: x-coredata:///Facility/tF1697911-CD8A-4D63-B40F-AB0CA020C873 notice the "t" in front of the objectID.

That's just how CoreData's url scheme works.

You have 2 persistent unique IDs to differentiate the object references.

MartinM
  • 832
  • 6
  • 12
  • ok. so then I can assume that the two are not identical? I have nested contexts, and I expected them to be equal, but it seems they are different after all somehow. In short `p1` and `p2` makes them different, since the `p{x}` is part of the object id. – Zsolt Dec 13 '18 at 13:06
  • It makes them unique across all contexts throughout the app. There needs to be some uniqueness to know how to apply changes happening on another context. As every managedObject has its associated context, you have a somewhat global reference with this URI. Otherwise it would not be possible to distinguish between objects without knowing which MOC to use. – MartinM Dec 13 '18 at 13:43