我有一個上下文,我想創建上下文中的現有對象(Veranstaltung)和新的對象之間的關係(門票)。單個上下文但「非法嘗試在不同上下文中的對象之間建立關係'xyz'
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]];
而且在設置事件,在App crashs .. 得到任何人的想法?謝謝!
錯誤中提到的是什麼關係?它實際上不是「xyz」,是嗎? – Caleb 2013-04-24 17:19:25
啊每次我都沒有提到,這不是「票」,它的「gekauftesTicket」,「票」反向「Veranstaltung」 – Jonathan 2013-04-24 17:24:45
@Jonathan你是如何解決你的問題? – SAHM 2013-11-28 15:03:54