Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CORE DATA objectId changes constantly

I have some data that I export into an XML file and put in a remote FTP Server.

I have to identified each object with a unique attribute, it doesn't matter wich is, but must be persistent always => it can never change.

I don't want to create a unique attribute, sequence, serial, etc.

I'm using the objectID but every time I use it a get a new reference.

I know that before the object has been saved, it has a 'temporal id', but once it's saved, it gets the definitive.

I'm not seeing this, never.

When I export, just fetch all data and loop, and always I get a new reference:

NSURL *objectID = [[personalDataObject objectID] URIRepresentation];

// some of id received for the SAME OBJECT (no changes made, saved, ...)
// 61993296
// 62194624

thanks,

r.

edit

I was using %d instead of %@, now the returned data is:

x-coredata://F46F3300-8FED-4876-B0BF-E4D2A9D80913/DataEntered/p1
x-coredata://F46F3300-8FED-4876-B0BF-E4D2A9D80913/DataEntered/p2
like image 543
mongeta Avatar asked Nov 29 '22 05:11

mongeta


1 Answers

The NSManagedObjectID is not guaranteed to be consistent. It can change based on a number of factors including data migration and other factors. If you are using this as a unique identifier for your objects, stop.

The only time you want to use the NSManagedObjectID is when you need to pass references between threads. Other than that situation you should not rely upon it for anything.

If you need a unique id then create one and store it in your entities.

like image 81
Marcus S. Zarra Avatar answered Dec 29 '22 08:12

Marcus S. Zarra