我有一个上下文,我想在上下文中的现有对象(Veranstaltung)和新对象(Ticket)之间创建关系。
NSManagedObjectContext *managedObjectContext = [self managedObjectContext]; //constructor get the Context from the appDelegate
Ticket *ticket = [NSEntityDescription insertNewObjectForEntityForName:@"Ticket" inManagedObjectContext:managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Veranstaltung" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"vID == %@", veranstaltung.vID];
[fetchRequest setPredicate:predicate];
NSError *error = nil;
NSArray *fetchedRequests = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
NSLog(@"FetchedRequests count: %d", fetchedRequests.count);
if(fetchedRequests !=nil)
[ticket setEvent:fetchedRequests[0]];
在设置事件时,应用程序崩溃了..有人知道吗?谢谢!