我会将一些测试数据添加到我的核心数据库中。但是我的关系存在问题。当我尝试仅在第一个上添加2个核心数据对象时,关系是正确的(用sqlite Viewer检查这个) - 但我不知道,为什么?
有什么想法吗?
这是我的代码:
let newSubCraftCategoryObj = NSEntityDescription.insertNewObjectForEntityForName("CraftSubCategory", inManagedObjectContext: context) as CraftSubCategory
newSubCraftCategoryObj.text = "Test Sub Category"
let newUnitObj = NSEntityDescription.insertNewObjectForEntityForName("Unit", inManagedObjectContext: context) as Unit
newUnitObj.text = "m2"
let newCraftObj = NSEntityDescription.insertNewObjectForEntityForName("Craft", inManagedObjectContext: context) as Craft
newCraftObj.minServiceLife = 8
newCraftObj.maxServiceLife = 12
newCraftObj.unit = newUnitObj
newCraftObj.craftsubcategory = newSubCraftCategoryObj
let newCraftObj1 = NSEntityDescription.insertNewObjectForEntityForName("Craft", inManagedObjectContext: context) as Craft
newCraftObj1.minServiceLife = 7
newCraftObj1.maxServiceLife = 10
newCraftObj1.unit = newUnitObj
newCraftObj1.craftsubcategory = newSubCraftCategoryObj
所以第一个“newCraftObject”完全没问题,但是我的第二个对象中的类别和单元与“newCraftObj1”没有任何关系