Iphone – Creating a unique id for a Core Data program on the iPhone

cocoa-touchcore-dataiphone

I am having a bit of trouble figuring out this Core Data stuff. How do I create a new entry with a unique ID? In SQL I would just declare one field as an autoincrement field. I'm not seeing anything like that here, but I could just be missing something. I just want an auto incrementing NSInteger field, so when I manually add items to the database, I will have some form of reference to them.

Best Answer

Though i agree with what you said, there is an ID mechanism behind core data. ID are indeed managed by Core-Data but you can retrieve them with :

NSManagedObjectID *moID = [managedObject objectID];

For more informations see : Core Data Programming Guide