如何使NSManagedObject不会出错? [英] How to make NSManagedObject not fault?

查看:87
本文介绍了如何使NSManagedObject不会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在调试由另一个开发人员编写的一个大项目。该项目使用 CoreData 这是我很新。我有一个崩溃发生,由于一些 NSManagedObject 是一个错误(我对错误的理解很差),我想转换对象进入不是故障,看看它是否有帮助。阅读文档让我认为使对象不会故障等于到火灾故障什么是火),所以我决定通过调用它的任何方法来触发它,这个方法是 hasChanges 因为它不在方法的列表, t火灾故障。然而,即使调用此方法后,对象仍然是故障。任何人都可以给我一个例子,如何将 NSManagedObject 转换为无故障状态?

I'm currently debugging a big project written by another developer. The project uses CoreData which i am very new to. I'm having a crash which happens due to the fact that some NSManagedObject is being a fault(i have poor understanding of what fault is) and i would like to convert the object into "not fault" and see if it helps. Reading documentation made me think that to make object not fault is equal to to fire fault (again i have poor understanding of what is "to fire"), so i decided to fire it by calling any method on it, and this method is hasChanges since it's not in the list of methods which don't fire fault. However even after calling this method the object still remained being fault. Can anyone give me an example of how to convert NSManagedObject into "not fault" state?

推荐答案

注释中提到的异常是:

Terminating app due to uncaught exception 'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x1f0627a0 <x-coredata://E40418A0-A8E5-4340-865F-A9DA2E0095DD/CoreObject/p288>''

无法完成故障消息表明这不是简单地触发故障的问题。事实上,没有特殊的步骤来触发故障 - 你只是访问的属性,如果必要,故障自动启动。

The "could not fulfill a fault" message indicates that this is not simply a problem with firing the fault. In fact there are no special steps to fire a fault-- you just access the attributes, and if necessary, the fault fires automatically.

这个错误告诉你你正在做一些导致故障的东西,但是Core Data找不到你使用的实例的任何记录。这可能发生在某些情况下,例如:

What this error is telling you is that you're doing something that causes a fault to fire, but that Core Data can't find any record of the instance you're using. This can happen in certain scenarios, for example:


  1. 获取对象,并将其作为故障)

  2. 从Core Data中删除它,但保留对对象的引用(可能在实例变量中)

  3. 保存更改

  4. 尝试访问您在步骤1中获取的对象的属性。

  1. Fetch an object, and leave it as a fault (i.e. don't access any attributes)
  2. Delete it from Core Data, but keep a reference to the object (maybe in an instance variable)
  3. Save changes
  4. Try to access an attribute on the object you fetched in step 1.

使用对象查找属性值。但是你已经删除它,所以属性数据消失了。核心数据抛出此异常。

At this point Core Data would normally use the object to look up the attribute value. But you already deleted it, so the attribute data is gone. Core Data throws this exception.

还有一些其他情况可以触发这个 - 调用 reset 对象上下文,同时保持先前读取的对象周围,或删除持久存储(使得数据仍然存在于存储文件中,但该文件不再被加载)。通常,这意味着Core Data正在尝试在不再有效的对象上查找数据。

There are some other scenarios that can trigger this-- calling reset on a managed object context while keeping previously fetched objects around, or removing the persistent store (so that the data still exists in the store file, but the file isn't loaded anymore). In general it means Core Data is trying to look up data on an object that's no longer valid.

您需要做什么:


  • 找出导致此问题的对象。设置异常断点,以便调试器在崩溃发生时加载,这可能是一个好主意。

  • 除去该对象。防止故障触发可能会防止这种特定的崩溃,但只要你仍然有这个对象,它就像一个土地矿在你的应用程序。它会爆炸并崩溃的应用程序,只要你触摸它。

  • 找出为什么你有无效的被管理对象潜伏在内存中。也许你应该早些摆脱他们?也许你不小心删除了不想删除的内容?由于某种原因,当受管对象不再有效时,它们会保留。这是导致您麻烦的核心问题。

  • Figure out which object is causing this. Setting an exception breakpoint, so that the debugger loads just as the crash is happening, is probably a good idea.
  • Get rid of that object. Preventing the fault from firing might prevent this specific crash, but as long as you still have this object, it's like a land mine in your app. It will explode and crash the app as soon as you touch it.
  • Figure out why you have invalid managed objects lurking in memory. Maybe you should have gotten rid of them earlier? Maybe you're accidentally deleting something you don't want to delete? For some reason you're keeping managed objects around when they're no longer valid. This is the core problem that's causing your trouble.

这篇关于如何使NSManagedObject不会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆