我建立一個IOS應用程序,我有以下問題類的關係:CoreData和實施協議
我說一類Animal
含有類Cats
和Dogs
。這些類別又分爲DomesticCats
,WildCats
(分別爲DomesticDogs
,WildDogs
),其中包含貓和狗的物種,其中一些是家養動物,而另一些則不是。
我有另一個類PetOwner
其中將包含一個對多關係petsSet
要麼DomesticCats
或DomesticDogs
的情況下,反比關係是owner
。
有沒有在我的應用的CoreDate模型中建立這種關係的方法? 它不是CoreData我會定義一個協議<DomesticAnimal>
,DomesticCats
和DomesticDogs
將實現,包含(其他)屬性owner
,但我不認爲我可以將它與CoreData模型混合?
或者我需要在我的CoreData模型來創建一個一對多的關係形式PetOwner
到Animal
,但我可以強制執行,只有實現<DomesticAnimal>
類將永遠被添加到PetOwner
的petsSet
?