1

In iOS 9, I can specify certain attributes in an entity to be unique constraints to prevent managed objects with the same unique constraints to be created.

Each NSManagedObject has its own ObjectId but maintained internally by Core Data and cannot be set as unique constraint in the model.

Based on that notion, does it make sense to include a "primary key" attribute for all entities in core data and specify the primary key as unique constraint if I don't want duplicate data?

imObjCSwifting
  • 743
  • 1
  • 12
  • 34

1 Answers1

0

If you have a meaningful way to source and populate that key, and the elimination of duplicates means something to you, then yes.

If you don't have a source of a meaningful value for the key, like a server generated value, then all you're doing is adding a requirement that you need to find the key first, and you'd be doing that anyway to avoid duplication. So adding it without 'external' support generally won't help.

Wain
  • 118,658
  • 15
  • 128
  • 151