我一直在试图获得核心数据实体间工作关系的单一任务。我已经实现了这一点,但现在我需要对其进行更改,以便新属性值将其关系添加到现有对象中。它是一对多的数据库。在核心数据中添加关系
我不知道如何将关系添加到已存在的对象。因此,在添加到RoutineDetail的新对象中,我将如何创建与例程实体中已存在的对象的关系?
我看过几个例子都显示如何添加关系到新添加的对象,但我需要它,因此RoutinesDetails
中的新对象与Routines
中已存在的值有关系。
的Routines
值在一个字符串举行名为RoutineText
rout is the NSmangedObject for the entity Routines
routDet is the NSmanagedObject for the entity RoutinesDetails
我已经离开了注释掉的代码,让我创建了两个新对象时添加的关系。
这是我不得不在我的项目中做的最后一件事,但它让我疯狂。我会永远感谢这里的修复。任何建议将不胜感激,因为这是最好的知识门户。谢谢。
NSManagedObjectContext *context = [self managedObjectContext];
// Create a new device
ExcerciseInfo *info = [_fetchedResultsController objectAtIndexPath:indexPath];
//rout = [NSEntityDescription insertNewObjectForEntityForName:@"Routines" inManagedObjectContext:context];
routdet = [NSEntityDescription insertNewObjectForEntityForName:@"RoutinesDetails" inManagedObjectContext:context];
//Add attribute values
//[rout setValue: RoutineText forKey:@"routinename"];
[routdet setValue: info.name forKey:@"image"];
//Create Relationship
[rout addRoutinedetObject:routdet];
什么是不工作? – Mundi
昨天你问的不是这个问题吗? http://stackoverflow.com/questions/17686651/core-data-relationship-add-to-existing-value –