ios:CoreData实体继承

时间:2015-05-21 07:26:13

标签: ios entity-framework core-data

在我的ios应用程序中,我有许多模型类,如ProjectLead,TeamLead,ProjectManager,Developer,所有这些类都在扩展Employee基类。

class Employee{
string name,age,company;
}

class ProjectLead: Employee{
  string pl_1,pl_2,pl_3;
}

class TeamLead:Employee{
string tl_1,tl_2,tl_3;
}
class ProjectManager:Employee{
string pm_1,pm_2,pm_3;
}
class Developer:Employee{
string d_1,d_2,d_3;
}

我可以为我的所有5个模型类创建单独的实体。我是否需要为子实体提供父实体属性。如何在EntityModel

中的实体定义中实现继承
for example Creating ProjectManager Entity

I can add pm_1,pm_2,pm_3 as its attributes, since its extends Employee I have another 3 attributes like name,aga,company. while creating ProjectManage entity Will i have to create it with 3 attributes or 6 attributes?

我只想为我的模型类创建实体,如http://www.raywenderlich.com/934/core-data-tutorial-for-ios-getting-started

1 个答案:

答案 0 :(得分:1)

看一下这篇文章,它解释了如何在核心数据中使用继承。 https://byunsoo.wordpress.com/2013/03/27/inheritance-in-core-data/

创建实体时(例如项目负责人),您可以在数据模型检查器中选择父实体(例如Employee)。

虽然确实有一些权衡,也要经历过它们 Core Data entity inheritance --> limitations?