核心数据动态实体 [英] core data dynamic entities
问题描述
我想要能够根据将在另一个实体中定义的属性创建一个动态实体。例如:
实体:Lifeform
Attribute-> name:String
实体:LifeformCharacteristics
Attribute-> name:String
Attribute-> type:String
实体:DynamicCatalog
因此,特征实体将是将由用户添加的任何内容填充的实体。示例特性可以是名称:高度类型:数字。所以这些特性定义了我想要的动态目录。因此,DynamicCatalog应使用属性Height创建。
DynamicCatalog也必须在表中可见,以便用户可以向目录添加和删除项目。
我可以通过我的DataModel构建和管理前两个实体,但第三个是动态的,我不知道如何去做。我希望使用核心数据使管理数据的头痛最小化。
这个帖子是我找到的答案最接近的,但我不知道现在显示或重组一个集合,像这样:在Core Data中创建动态模式?
考虑在Core Data中创建一个to many的DynamicCatalog类型,与称为DynamicCatalogValue的东西的关系或者一些环绕语义铃声的名称。在值上创建允许用户描述的属性。例如(pseudo):
DynamicValue:
属性:userGivenName;
属性:userGivenValue;
属性:valueType; (例如String,Date等)
I want to be able to create a dynamic entity based on attributes that will be defined in another entity. For example:
Entity:Lifeform Attribute->name:String
Entity:LifeformCharacteristics Attribute->name:String Attribute->type:String
Entity:DynamicCatalog
So the characteristics entity will be a entity that will be populated by whatever the user adds. An example characteristic could be name:Height type:Number. So these characteristics define what I want the dynamic catalog to be. As such the DynamicCatalog should be created with the attribute Height.
The DynamicCatalogs will also have to be visible in a table so the user can add and remove items to the catalogs.
I can build and manage the first 2 entities via my DataModel, but the 3rd is dynamic and I'm not sure how to go about it. I was hoping to use core data to keep the headache of managing data to a minimal.
This post is the closest thing I've found to an answer, but I'm not sure now to display or reorganize a collection like this: Faking a dynamic schema in Core Data?
Why cause yourself so much trouble?
Consider creating the DynamicCatalog type in Core Data with a 'to many' relationship to something called 'DynamicCatalogValue' or some name that rings the semantic bell. Create attributes on the 'Value' that you will allow the user to describe. For example (pseudo):
DynamicValue:
Attribute: userGivenName;
Attribute: userGivenValue;
Attribute: valueType; (e.g. String, Date, etc.)
这篇关于核心数据动态实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!