Objective C - 核心数据关系
我的核心数据关系有问题。 我向方法 addData 传递了一个数据数组。它是一个字典数组。每个字典都有 3 个键,“A”、“B”、“C”。键 C 存储另一个具有 3 个键的字典数组。 第一个数组是项目类型,第二个数组是项目子类型。 现在,我如何将它放入 CoreData 中?实体名称是“Type”和“Subtype”。 我如何从 CoreData 获取它? 谢谢
i've a problem with Core Data relationship.
I pass to my method addData an array of data. It is an array of dictionary. Every dictionary have 3 keys, "A", "B", "C". Key C store another array of dictionary that have 3 keys.
The first array is of item Type and the second of item Subtype.
Now, how can i place it into CoreData?The entity name is "Type" and "Subtype".
And how can i take it from CoreData?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个
Type
实体,该实体将具有属性a
和b
以及关系c
(小写以符合与命名约定)。c
与Subtype
实体是一对多关系。 Subtype 实体具有三个属性,一个属性对应字典的每个键,还有一个关系type
,该关系是Type
对象的c
的逆关系。使用以下伪代码(我不关心设置核心数据的细节。您可以轻松阅读 docs) 帮助您创建一个解决方案来填充原始模型字典数组。
下次您从核心数据存储中获取类型管理对象时,所有这些都将已设置完毕。
将返回该 Type 对象的子类型对象的数组。
You need an entity for
Type
which will have attributesa
andb
and a relationshipc
(lower case to conform with naming conventions).c
is a 1 to many relationship to theSubtype
entity. The Subtype entity has three attributes, one for each of the dictionary's keys and a relationshiptype
which is the inverse relationship for theType
object'sc
.Use the following pseudocode (I can't be bothered with the detail of setting up core data. You can easily read the docs) to help you create a solution to populate your model from the original array of dictionaries.
Next time you fetch the Type managed object from the core data store, all that will be set up already.
will return an array of the subtype objects for that Type object.