iphonecore-dataprimary-keynsentitydescription

How to create unique identifier for an entity in iphone core data


I am new to core data and iphone programming so dont mind my silly qn. I couldn't figure out how to mark a attribute as a primary key in the xcdatamodel file or may be outside. I looked around and found some people saying that it is not possible.

I am getting identifier for every object that i am getting, i would need to store that object through core data and i might need to use that identifier in my web service to retrieve additional data. How do i keep the primary key of an entity equal to that identifier, any help is greatly appreciated.

Thanks in advance,

Yogesh


Solution

  • In short you cannot mark an attribute as primary key automatically. You have maintain one by your own.

    You can do anyone of the below:

    Use [NSManagedObject objectID].

    Your own primary key-like system that stores an integer in your model and increments it with the creation of each object