try the URIRepresentation
property of NSManagedObjectID
. this is very unique ID for the current NSManagerObject
but be careful until the NSManagedObject
is not saved it gives you a temporary ID only, not a permanent one and they might be different. (I'm just saying it because I don't know for what and how you want to use the unique ID.)
UPDATE #1
this is not an imaginary unique ID only, this is pure unique URL for each individual NSManagedObject
(like every file has a unique URL), using them you can find again the original NSManagedObject
, after you lost their pointer. I know it is hard to understand, but this is the point of the NSManagedObjectID
and its properties.
(if you don't understand how the CoreData
and their objects work, you would not downvote the answer. please, read more documentation instead of the pointless downvoting.)
UPDATE #2
according to @NickLocking comment, I would extend the bold part of my answer above:
until saving the NSManagedObjectContext
for the the new and still unsaved NSManagedObject
classes has a temporary unique ID only. They will get the permanent unique ID after they are saved at first time.
NSManagedObjectID
will be change after the first saving of the context then the object will get the finalNSManagedObjectID
, and it won't be changed ever. you should not worry about the exists IDs then, not even you deleted theobject
because no newobject
will get the old ID. – Rashad