管理对象上下文删除然后保存对象会引发objc_exception_throw错误

时间:2010-02-22 12:20:29

标签: iphone exception core-data

尝试在managedObjectContext上调用save方法时出现以下错误。

#0  0x939214e6 in objc_exception_throw
#1  0x01ded83b in -[NSObject doesNotRecognizeSelector:]
#2  0x01d84676 in ___forwarding___
#3  0x01d606c2 in __forwarding_prep_0___
#4  0x01c618b6 in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:]
#5  0x0003263a in _nsnote_callback
#6  0x01d4f005 in _CFXNotificationPostNotification
#7  0x0002fef0 in -[NSNotificationCenter postNotificationName:object:userInfo:]
#8  0x01bc217d in -[NSManagedObjectContext(_NSInternalNotificationHandling)     _postObjectsDidChangeNotificationWithUserInfo:]
#9  0x01c21763 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:]
#10 0x01ba65ea in -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:]
#11 0x01bdc728 in -[NSManagedObjectContext save:]
  • 我在转到以下代码之前对OrderItem实体做了一些更改,我想取消对OrderItem的任何插入

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    [fetchRequest setEntity:[NSEntityDescription entityForName:@"OrderItem" inManagedObjectContext:managedObjectContext]];
    NSArray *deleteItems = [managedObjectContext executeFetchRequest:fetchRequest error:&error];
    for (id item in deleteItems)
        [managedObjectContext deleteObject:item];
    
    if (![managedObjectContext save:&error]){
        NSLog(@"deleting OrderItem failed: %@, %@", error, [error userInfo]);
        return FALSE;
    }
    

错误发生在[managedObjectContext save:& error]行上而没有转到NSLog但引发异常。

我做错了什么?有人告诉我怎么样?

1 个答案:

答案 0 :(得分:0)

我的.xcdatamodel中有复杂的架构,其中OrderItem与将DeleteRule设置为Nullify 有两个关系。

暂时更改为“无操作”解决了错误,即使提出了一些警告,但我个人认为, xCode不应该那样行事。它应该将值填充到& error以告诉我我的架构有问题。

对此有何想法?