I’m a long time listener, but first time caller here… Hoping you can help me with a core data question!
I am creating a custom business app for iPad that allows a user to fill out contracts commonly used in their business. There are four contracts with between 20 and 40 data fields each and they are all quite different, but there are a few (3-4) fields that are common to all four, such as Date Created and Vendor Name etc.
I need to display all the contracts together in a UITableView (grouped style to show there are different types), and I need to be able to select a cell and display a detail view so the user can view and modify data on a specific contract.
My research to date tells me I should use a parent entity (entity A) that lists the attributes common to all, and then child entities (entity B, C, D, & E representing each of the four contracts) that have the attributes unique to them, and inherit the rest from entity A.
Is this the best way to structure this data model? Bearing in mind that when I create a new instance of a contract it needs to be a standalone object with all its attributes plus that of the parent. If so, when I’m generating cells for my tableView, do I fetch entity A and hope the rest come along also, or do I do separate fetch requests for each contract type and add to the table that way? Conversely, if I want to create a new instance of a contract (say entity B in my data model) how would I go about that?
I hope I’ve explained that well enough. Thanks for your help with this!
You should create an abstract entity with your common fields, and inherit your different contract types from there. From the documentation:
This will also enable you to define common behaviours for all your contracts and use the abstract superclass in your code to refer to any contract.