本文介绍了核心数据:-deleteObject:崩溃,是删除规则原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有以下模型,您可以在图片中看到。 我的应用程序需要刷新B的每个实例,因此在每个 viewWillAppear ,我需要删除模型中的所有B。在删除B时,关于C的级联删除规则将删除所有C,然后级联到所有D. A& E是常数。 每个对象上都有DeleteRule,如下所示: A:b - Cascade B:c - Cascade,a - Nullify C:b - Nullify,d - Cascade D:c - Nullify,e - Nullify E:d - 级联 或 A - (cascade) - >> B - (级联) - > C - (级联) - > D((无效)) - E A pre> 我有在所有B,C,D上级联删除的问题。我的fetchRequest对象返回A中的每个B的实例,然后我从managedObjectContext调用每个B上的 -deleteObject:。但有对[managedObjectContext save:& error] 调用的EXC_BAD_ACCESS。 有人可以告诉我我做错了什么?我在每个实体上有DeleteRule的问题,或者问题在别处吗?在三个对象B,C,D上处理级联删除的最佳做法是什么? 已编辑: 下面是当引发错误的堆栈跟踪: 在___forwarding___ $ b#0 0x01d843ae $ b#1 0x01d606c2在__forwarding_prep_0___ #2 0x01c618b6中 - [NSFetchedResultsController(PrivateMethods)_managedObjectContextDidChange:] #3 0x0003263a在_nsnote_callback #4 _CFXNotificationPostNotification 0x01d4f005 #5 0x0002fef0在 - [NSNotificationCenter postNotificationName:对象:用户信息:] #6 0x01bc217d在 - [的NSManagedObjectContext(_NSInternalNotificationHandling)_postObjectsDidChangeNotificationWithUserInfo:] #7 0x01c21763在 - [的NSManagedObjectContext(_NSInternalChangeProcessing)_createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] #8 0x01ba65ea在 - [的NSManagedObjectContext(_NSInternalChangeProcessing)_processRecentChanges:] #9 0x01bdc728在 - [NSManagedObjectContext中保存:] 这是控制台中的日志,当我试图设置NSZombieEnabled& MallocStackLogging为YES: 2010-02-24 15:41:39.803 Foo [2591:207]删除对象:FUM5 2010-02-24 15:41:40.515富[2591:207] *** - [的viewController controllerWillChangeContent:]:发送到释放的实例0x7e54510 信息 编辑2:SOURCE CODE ADDED 我已尝试通过创建一个具有图像中确切模式的新项目。您可以从这里下载。还有一个README文本。希望我给了足够的信息。 解决方案 你在做你的 NSFetchedResultsControllerDelegate 方法?基于堆栈跟踪它看起来像你在做一些有趣的事情之一。理想情况下,这些代理只应该更新它们所附加的 UITableView 。如果你在其中一个方法中使用 NSManagedObject 实例或 NSManagedObjectContext 执行某些操作, this。 我建议在 objc_exception_throw 上放置一个断点,问题正在发生。 更新 我看过代码, A具有该B的必需属性。这导致验证错误。您不能删除另一个对象具有必需关系的对象。 I have the following model, as you can see in the image.My application requires refreshing every instance of B, so at each viewWillAppear, I need to delete all the B's in the model. Upon deleting a B, the cascade delete rule on the relationship to C will delete all C and then cascade to all D.A & E are constants.I have the DeleteRule on each object as follows:A: b - CascadeB: c - Cascade, a - NullifyC: b - Nullify, d - CascadeD: c - Nullify, e - NullifyE: d - Cascadeor A -(cascade)->> B -(cascade)-> C -(cascade)->> D -(nullify)-> EA <-(nullify)- B <-(nullify)- C <-(nullify)- D <-(nullify) EI am having problem with cascading the delete on all B,C,D. My fetchRequest object returns every instance of B in A and then I call the -deleteObject: on each B from the managedObjectContext. But there is the EXC_BAD_ACCESS on the call to [managedObjectContext save:&error].Can someone show me what I am doing wrong? Am I having problems with the DeleteRule on each entity or does the problem lay elsewhere? What are the best practices to handle the cascading deletes on three objects B,C,D?Edited:Here is the stack trace when the error is raised: #0 0x01d843ae in ___forwarding___ #1 0x01d606c2 in __forwarding_prep_0___ #2 0x01c618b6 in -[NSFetchedResultsController(PrivateMethods) _managedObjectContextDidChange:] #3 0x0003263a in _nsnote_callback #4 0x01d4f005 in _CFXNotificationPostNotification #5 0x0002fef0 in -[NSNotificationCenter postNotificationName:object:userInfo:] #6 0x01bc217d in -[NSManagedObjectContext(_NSInternalNotificationHandling) _postObjectsDidChangeNotificationWithUserInfo:] #7 0x01c21763 in -[NSManagedObjectContext(_NSInternalChangeProcessing) _createAndPostChangeNotification:withDeletions:withUpdates:withRefreshes:] #8 0x01ba65ea in -[NSManagedObjectContext(_NSInternalChangeProcessing) _processRecentChanges:] #9 0x01bdc728 in -[NSManagedObjectContext save:]Here is the log in the console when I tried to set NSZombieEnabled & MallocStackLogging to YES: 2010-02-24 15:41:39.803 Foo[2591:207] deleting object: FUM5 2010-02-24 15:41:40.515 Foo[2591:207] *** -[viewController controllerWillChangeContent:]: message sent to deallocated instance 0x7e54510Edit 2: SOURCE CODE ADDEDI have tried to recreate the situation by creating a new project with the exact schema in the image. You can download it from here. There is a README text as well. Hope that I have given enough information. 解决方案 What are you doing in your NSFetchedResultsControllerDelegate methods? Based on the stack trace it looks like you are doing something funny in one of those. Ideally those delegates should only be updating the UITableView that they are attached to. If you are doing something either with the NSManagedObject instances or the NSManagedObjectContext in one of those methods it can cause a crash like this.I would suggest putting a breakpoint on objc_exception_throw and that can give you more information about the exact point the issue is occurring.UpdateI have looked at the code and you are trying to delete a B while A has a required property for that B. This is causing a validation error. You can't delete an object that another object has as a required relationship. 这篇关于核心数据:-deleteObject:崩溃,是删除规则原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-23 06:07
查看更多