i need to set up a IS-A relationship with coredata.
I have a Page class which has the following structure
PROPERTY title
PROPERTY layoutType
RELATIONSHIP layout
Now, i have three classes: ImageLayout, TextLayout, and SlideshowLayout.
I want the Page.layout relationship to refer to one of these three classes depending on the layoutType property.
How can i do with coredata?
Or there is another way to do this? Keep in mind that the number of layouts can grow in the future, so i can’t simply put all the properties in page and leave empty the ones that are not related to the layout of the page.
Thank you in advance!
You use entity inheritance. You create a parent entity that can be abstract or concrete. Then you assign the parent to the
Page.layoutrelationship. When you need different finds of layouts, you create subentities (like a subclass) of the parent. The object graph will accept any subentities in the relationship.E.g. Create an abstract entity called layout. It may have no attributes save the relationship like so (pseudocode):
You can assign any single instance of ImageLayout, TextLayout or SlideshowLayout to the
Page.layoutrelationship of anyPageinstance.