NSObjectInaccessibleException',reason:'CoreData无法完成故障 [英] NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault

查看:270
本文介绍了NSObjectInaccessibleException',reason:'CoreData无法完成故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的iOS应用程式透过多个主题使用核心资料。我收到一些崩溃报告与以下消息:'NSObjectInaccessibleException',原因:CoreData不能完成'0x1e07a9b0'的错误

My iOS app uses core data via multiple threads. I am getting some crash reports with the following message: "'NSObjectInaccessibleException', reason: 'CoreData could not fulfill a fault for '0x1e07a9b0 ''

这个问题 - 对象被删除,但另一个线程正在尝试访问它。我正在努力解决问题,但我想在后台线程中添加一个检查,以查看对象是否会以这种方式故障。

I understand what is causing this problem - that the object was deleted but another thread is trying to access it. I am working to solve the problem but I want to add a check in the background thread to see if the object will fault in this manner.

我现在的代码与 myObject.myValue 有关,可以做一些检查,例如:

My code at the moment relates to myObject.myValue. Is it possible to do some check, such as:

if (!myObject.myValue) {
    return;
}

...所以它会在执行任何可能导致这种崩溃的方法之前退出方法或者将简单地调用

... so that it will get out of the method before doing anything that could cause such a crash? Or will simply calling myObject.myValue, even to see if it's null, cause such an exception to be thrown?

推荐答案

您可以尝试使用 existingObjectWithID:error:

You could try and use existingObjectWithID:error::




Returns the object for the specified ID.

   - (NSManagedObject *)existingObjectWithID:(NSManagedObjectID *)objectID error:(NSError **)error

讨论

有一个已经在上下文中注册了给定ID的被管对象,该对象被直接返回;

If there is a managed object with the given ID already registered in the context, that object is returned directly; otherwise the corresponding object is faulted into the context.

如果数据未被缓存,此方法可能会执行I / O。

This method might perform I/O if the data is uncached.

与objectWithID:不同,此方法不会返回错误。

Unlike objectWithID:, this method never returns a fault.

您可以使用dO:

if ([myMOC existingObjectWithID:myObject.objectID error:&error])
    ...

这篇关于NSObjectInaccessibleException',reason:'CoreData无法完成故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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