When working with CoreData, do I need to create an ID attribute to have some sort of unique key for each record or can I access the data base ID field per each line in the table?
If there's a way to use the DB ID field, I would appreciate some direction about how to get to it when saving the record via the managedObject instance...
Usually there is no need to create a id attribute because every object has an object ID (NSManagedObjectID). If you have a managed object you get it's id by sending -objectID to it. There is a catch though:
There is a catch: An NSManagedObjectID can be either temporary or permanent. When an object is created it has a temporary ID until you obtain a permanent ID for the object. When you persist an object Core Data automatically obtains a permanent ID for each object which still have temporary IDs.
If you need a custom ID attribute you should create it for each entity individually. Do not create an abstract entity with an ID attribute. If you do that Core Data will create a huge (monster) table for all entities that inherit from the abstract entity. This is bad.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With