为了账号安全,请及时绑定邮箱和手机立即绑定

Coredata错误“数据:<故障>”

Coredata错误“数据:<故障>”

手掌心 2019-12-25 14:27:24
我尝试使用以下代码从CoreData中提取数据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个对象。所以谓词应该起作用,但是我在控制台中得到了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>)",)在我对Cave.m(即实体)进行以下更改之前,它一直运行良好我在Cave.h中将MKAnnotation添加为委托,并在Cave.m中添加了此代码。- (CLLocationCoordinate2D)coordinate{    CLLocationCoordinate2D location;    location.latitude = [self.latitude doubleValue];    location.longitude = [self.longitude doubleValue];    return location;}有办法调试吗?
查看完整描述

2 回答

?
慕姐4208626

TA贡献1852条经验 获得超7个赞

从CoreData提取数据时,我遇到了同样的问题!因此,我按照@jrturton的指示在Swift 3中实现了它:


步骤1:新增 import CoreData


步骤2:添加以下代码。。


let context = ( UIApplication.shared.delegate as! AppDelegate ).persistentContainer.viewContext

var request = NSFetchRequest<NSFetchRequestResult>()

request = Your_Entity_Name.fetchRequest()

request.returnsObjectsAsFaults = false

do {

    let arrayOfData = try context.fetch(request)

} catch {

    // Handle the error! 

}

希望会对您有帮助。:)


查看完整回答
反对 回复 2019-12-25
  • 2 回答
  • 0 关注
  • 528 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信