0
我在CoreData模型“Valla”和“Dagbok”中有两个实体,这些实体与多对多关系相关。核心数据添加与fetchRequest结果相关的新实体文章
当我向Dagbok实体添加一个新帖子时,我希望它与来自Valde实体的帖子相关联,该实体存储在FetchRequest的NSArray中。
的代码,现在只是增加了一个帖子Dagbok
- (void)initDagbokDBWithText:(NSString *)text header:(NSString *)header degree:(int)degree weather:(NSString *)weather farg:(NSString *)farg
{
AppDelegate *appdelegate = [[UIApplication sharedApplication]delegate];
context = [appdelegate managedObjectContext];
NSEntityDescription *entitydesc = [NSEntityDescription entityForName:@"Dagbok" inManagedObjectContext:context];
NSManagedObject *newDagbok = [[NSManagedObject alloc] initWithEntity:entitydesc insertIntoManagedObjectContext:context];
//NSRelationshipDescription *dagbokRelation = [[NSRelationshipDescription alloc] init];
//NSRelationshipDescription *vallaRelation = [[NSRelationshipDescription alloc] init];
[newDagbok setValue:text forKey:@"text"];
[newDagbok setValue:header forKey:@"header"];
[newDagbok setValue:[NSNumber numberWithInt:degree] forKey:@"degree"];
[newDagbok setValue:weather forKey:@"weather"];
[newDagbok setValue:farg forKey:@"colorCode"];
NSError *error;
if(![context save:&error])
{
NSLog(@"Whoops : %@", [error localizedDescription]);
}
}
如何从与fetchRequest结果阵列添加相关的对象?