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

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.


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


That ain't how CoreData works.

In CoreData, you create instances of entities. Each instance is unique. You then retrieve and manipulate instances as needed. CoreData takes care of the persistence for you, including uniquely identifying instances.

Step away from everything you know about traditional relational databases.

CoreData is an awesomely powerful bit of technology that offers features well beyond just database like persistence. It'll save you many lines of code and perform extremely well if you embrace it.