作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将外部数据添加到 SQLite 中/使用 Core Data 更新现有数据。
基本上,我从外部 Web 服务获得了一个 JSON,我正在使用以下代码来确定我是应该在数据库中添加新对象还是更新现有对象。
NSFetchRequest *fetch = [[NSFetchRequest alloc] init];
[fetch setEntity:[NSEntityDescription entityForName:@"name" inManagedObjectContext:context]];
[fetch setPredicate:[NSPredicate predicateWithFormat:@"id = %@", [data valueForKey:@"key"]]];
NSArray *results = [context executeFetchRequest:fetch error:nil];
if (results.count == 1)
{
// update existing
}
else
{
// add new
}
问题是:有时这段代码会导致异常:
Thread 1: EXC_??? (11) (code=0, subcode=0x0)
在 NSManagedObjectContext executeFetchRequest:error:
中引发异常
如果我继续执行我的应用程序,一切似乎都正常。
我应该担心这个异常吗?
我的意思是拥有它有点烦人,但更重要的是了解此异常的原因和后果是什么?
一些额外的细节(以防万一):
[编辑]更多细节:
executeFetchRequest:error
即使在引发异常时也返回初始化数组。executeFetchRequest:error
提供 error
参数时没有设置错误 最佳答案
那不安全。
您应该检查方法的返回以确保您返回了一个数组
NSArray *results = [context executeFetchRequest:fetch error:nil];
if (!results) {
// An error occurred you should probably use the out error
}
而且 CoreData 似乎在内部抛出异常但会处理它们,因此如果您设置了异常断点,它很可能会在 CoreData 堆栈的随机点被捕获 - 我是根据过去的经验说的,不确定它是否在任何地方记录但在这个视频中提到了Debugging Tips - Mike Hay
关于ios - EXC_???在执行 executeFetchRequest 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14812611/
我正在尝试将外部数据添加到 SQLite 中/使用 Core Data 更新现有数据。 基本上,我从外部 Web 服务获得了一个 JSON,我正在使用以下代码来确定我是应该在数据库中添加新对象还是更新
我是这里的新手和 iphone 应用程序开发人员。 有时我会在通过模拟器运行我的应用程序时看到此错误和应用程序崩溃。 使用 xcode 4.4.1、Mountain Lion、iOS 5.1。 我猜这
我是一名优秀的程序员,十分优秀!