我正在尝试将已经在类别中的值链接到 wod 实体。因为我确实想为每个类别的 wod 记录调用一个新记录。不知道该怎么做。我正在考虑使用谓词,但我不确定如何将它从获取请求中链接。
这就是我的架构的样子:
这是尝试将它们链接在一起的代码:
NSManagedObjectContext *context = [self managedObjectContext];
Wod *wodInfo = [NSEntityDescription
insertNewObjectForEntityForName:@"Wods"
inManagedObjectContext:context];
[wodInfo setValue:@"Frank" forKey:@"name"];
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
[request setEntity:[NSEntityDescription entityForName:@"Categories"
inManagedObjectContext:context]];
[request setPredicate:[NSPredicate predicateWithFormat:@"(name == %@", @"Time"]];
// This is the part where i am unsure, since i am not exactly sure how to link them up
Category *category = reques
wodInfo.category =
NSError *error;
if (![context save:&error]) {
NSLog(@"Whoops, couldn't save: %@", [error localizedDescription]);
}
任何帮助将不胜感激。