开发者

Managed object context deleting then saving objects raises objc_exception_throw error

I have the following error while trying to call the save method on managedObjectContext.

#0  0x939214e6 in objc_exception_throw
#1  0x01ded83b in -[NSObject doesNotRecognizeSelector:]
#2  0x01d84676 in ___forwarding___
#3  0x01d606c2 in __forwarding_prep_0___
#4  0x01c618b6 in -[N开发者_运维知识库SFetchedResultsController(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:]
  • I did some changes to the OrderItem entity before coming to this following code, where I want to cancel any insertion to 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;
    }
    

The error occurs on the line [managedObjectContext save:&error] without going to the NSLog but raises an exception.

What am I doing wrong? Someone show me how, please?


I have the complex schema in my .xcdatamodel in which the OrderItem has two relationships with the DeleteRule be set to Nullify.

Temporarily change to "No Action" solves the error even though it raises some warnings, but personally I think, xCode should not behave that way. It should populate the values to &error to let me know I have problems with my schema.

Any thoughts about this?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜