CoreData与MapKit无法识别的选择器

时间:2011-09-05 06:12:24

标签: iphone core-data unrecognized-selector

我收到以下错误

2011-09-05 08:08:43.506 CaveConditions[7203:11903] -[NSManagedObject coordinate]: unrecognized selector sent to instance 0x7471910
2011-09-05 08:08:43.507 CaveConditions[7203:11903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject coordinate]: unrecognized selector sent to instance 0x7471910'

这就是我所说的

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

    [self.mapView addAnnotations:[self.context executeFetchRequest:request error:NULL]];

它在addAnnotations行崩溃

在我的Cave.h中(它作为MKAnnotation代表)

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

在我的Cave.m

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

我错过了什么吗?

enter image description here

1 个答案:

答案 0 :(得分:4)

该错误表明Cave类未在数据模型中注册为实体Cave的类。执行提取时,将返回通用NSManagedObject而不是Cave类的实例。

检查数据模型是否具有要放入自定义NSManagedObject子类名称的字段。它可能仍设置为默认值。