Coredata chained Relationship

时间:2016-02-03 03:07:41

标签: ios swift core-data swift2 relationship

What is the best way to update or add data if relationships are chained.

I have my coredata designed like this:

Relationship

I have 3 Entities

1) User To_Many Category

2) Category To_Many Item

3) Item To_One Category

User is required before adding a Category, and Category is required before adding an Item

1 个答案:

答案 0 :(得分:1)

简单。只需设置一对一关系,相应的反向关系将由Core Data自动设置。

newItem.category = category
category.user = user

根据最佳做法,我将笨拙的属性名称itemCategorycategoryUsercategoryInUser重命名为categoryuser,{分别为{1}}。