I'm building a simple app in Swift using Core Data and trying to decide if I should store a unique id in my entities. In my research, I have found examples of that do and examples that don't, but I haven't found any clear reasoning behind this kind of decision.
Please note:
- I come from a RDBMS background and I know that Core Data is an object graph, not a relational db
- I do know that Core Data creates an NSManagedObjectID
, but how do I determine if that will be enough
I see threads like this (from 7 years ago, by the way) which lays out these options:
- Use -[NSManagedObject objectID]. Note that this ID is temporary until either the object is saved for the first time or you call
- [NSManagedObjectContext obtainPermanentIDsForObjects:error:] Use the CFUUID family of functions to generate a UUID for each object in your -awakeFromInsert method
- Create your own primary key-like system that stores an integer in your model and increments it with the creation of each object
but I haven't been able to find much information about which options are appropriate for which situations.
What questions should I be asking myself to figure out if Core Data's unique identifier (NSManagedObjectID) is all I need or if I should go beyond that and choose to include one of my own into the mix.