Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Auto-Incremented Object ID in Core Data?

I am working with several NSManagedObject types with several relationships. How can I tell Core Data to automatically populate object IDs for me? I'm looking for something like an index key in SQL, so that no two instances of a given object are allowed to have the same ID.

Edit:

I'd like for all of my "Account" objects to have unique IDs on them. I was just adding one to the `countForFetchRequest, but I realized that when deleting the second to last object and then adding one, the last two objects now have the same IDs.

How can I ensure that a given value has a unique value for all instances of my "Account" NSManagedObject?

EDIT2:

I need to have a separate ID for sorting purposes.

like image 468
Moshe Avatar asked Jun 16 '11 18:06

Moshe


1 Answers

All NSManagedObjects automatically have a unique NSManagedObjectID. There is no notion of a custom auto-incrementing attribute, but it's certainly easy to write one yourself.

like image 109
Barry Wark Avatar answered Sep 30 '22 19:09

Barry Wark