核心数据错误“数据:<故障>" [英] Coredata Error &quot;data: &lt;fault&gt;&quot;

查看:27
本文介绍了核心数据错误“数据:<故障>"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下代码从 CoreData 中提取数据

I try to pull out data from CoreData with the following code

NSFetchRequest *request = [[NSFetchRequest alloc] init];
request.entity = [NSEntityDescription entityForName:@"Cave" inManagedObjectContext:self.context];
request.predicate = [NSPredicate predicateWithFormat:@"(latitude > 0) AND (longitude > 0)"];

NSError *error;
NSLog(@"%@",[self.context executeFetchRequest:request error:&error]);
NSLog(@"%@",[error localizedDescription]);

CoreData 应该有 9 个匹配的对象,它会找到 9 个对象.所以谓词应该可以工作,但我在控制台中得到了这个

CoreData should have 9 matching objects and it finds the 9 objects. So the predicate should work but I get this in the console

2011-09-05 07:41:42.267 CaveConditions[6930:11903] (
    "<NSManagedObject: 0x7368060> (entity: Cave; id: 0x7367880 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p31> ; data: <fault>)",
    "<NSManagedObject: 0x73547e0> (entity: Cave; id: 0x7356e20 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p40> ; data: <fault>)",
    "<NSManagedObject: 0x73681e0> (entity: Cave; id: 0x7363e60 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p42> ; data: <fault>)",
    "<NSManagedObject: 0x7368280> (entity: Cave; id: 0x7356be0 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p72> ; data: <fault>)",
    "<NSManagedObject: 0x7368320> (entity: Cave; id: 0x733ad80 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p73> ; data: <fault>)",
    "<NSManagedObject: 0x73683c0> (entity: Cave; id: 0x7333e70 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p91> ; data: <fault>)",
    "<NSManagedObject: 0x7368480> (entity: Cave; id: 0x7361810 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p101> ; data: <fault>)",
    "<NSManagedObject: 0x7368570> (entity: Cave; id: 0x7360110 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p105> ; data: <fault>)",
    "<NSManagedObject: 0x7368610> (entity: Cave; id: 0x73303c0 <x-coredata://C825FC9D-3490-4D8A-A811-979B819A2EB6/Cave/p112> ; data: <fault>)"
)

它过去一直工作得很好,直到我在实体 Cave.m 中做了以下更改

It used to work prefectly fine until I did the following change in Cave.m which is the Entity

我在 Cave.h 中添加了 MKAnnotation 作为委托,并在 Cave.m 中添加了这段代码

I added MKAnnotation as a delegate in Cave.h and added this code in Cave.m

- (CLLocationCoordinate2D)coordinate
{
    CLLocationCoordinate2D location;
    location.latitude = [self.latitude doubleValue];
    location.longitude = [self.longitude doubleValue];
    return location;
}

有没有办法调试这个?

推荐答案

这是预期的行为,核心数据不会返回完整的对象,直到您需要访问对象的持久值.在此之前,您返回的每个对象都将是错误".

This is expected behaviour, core data won't return full objects until you need to access the persistent values of the objects. Each of your returned objects will be a 'fault' until this point.

您可以使用 [request setReturnsObjectsAsFaults:NO] 强制 fetch 请求返回完整的对象,但在大多数情况下,您所拥有的会很好.查看 NSFetchRequest 的文档以获取更多信息.

You can force the fetch request to return full objects using [request setReturnsObjectsAsFaults:NO], but in most cases what you have will be fine. Look at the documentation for NSFetchRequest for more information.

如果您访问其中一个属性,核心数据将转到持久存储并获取其余值,然后您将在日志中获得完整描述.

If you access one of the properties, core data will go to the persistent store and fetch the rest of your values, then you'll get the full description in the logs.

这似乎是一个如此普遍的误解,我决定写下它,这里.

This seems to be such a common misunderstanding that I decided to write about it, here.

这篇关于核心数据错误“数据:<故障>"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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