I’m using CoreData in an iOS app as my relational database. The relationships between the entities are a little complicated, but only a small number of objects (<40) are created. I’d like the user to build up the object graph, be able to save the object graph, build a new one, save it, return to the first one, etc. What is the best pattern for doing this?
I’ve thought about making all of my NSManagedObject subclasses conform to Codable (or make structs for storing each NSManagedObject’s relevant data), serializing all the data and saving to a file, and rebuilding the object graph when decoding. With this approach, I’d persist the object graph in my custom filetype, but never in CoreData per se. I suspect this isn’t the best approach for a CoreData application.
I’ve also been reading the docs for UIManagedDocument, but I’m not sure if this is the tool I need. I can’t find any examples of how it is used, and can’t quite grasp how to implement it (i.e., would I still need to make my NSManagedObject subclasses Codable?) Any direction or suggestion of how to proceed would be greatly appreciated.