Do NSManagedObjects come with any kind of unique identifier?
I need to fetch a couple of objects but there is a large chance they have identical attributes, so how can I, after fetching these objects, differentiate them?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes. Every NSManagedObject has an
-objectIdaccessor which returns anNSManagedObjectIDinstance. These uniquely identify the object in question. You can then retrieve the object again using either of NSManagedObjectContext’s methods-objectWithID:or-existingObjectWithID:error:.Note that if the object has not yet been saved after insertion, the object ID will be a temporary ID that will change when it’s saved. You can force a persistent ID to be assigned with
-[NSManagedObjectContext obtainPermanentIDsForObjects:error:], although this is just as expensive as an actual save.