我有一个托管对象MyEntity
,我在整个应用程序中都可以毫无问题地使用它。
@interface MyEntity : NSManagedObject
@property (nonatomic, retain) NSString *code;
@property (nonatomic, retain) NSNumber *def_value;
@property (nonatomic, retain) NSString *label;
@property (nonatomic, retain) NSString *link_label;
@property (nonatomic, retain) NSNumber *order;
@end
我有一个http://my_server/MyEntity
返回我的网络服务:
[
{
CODE: "TYPE",
LABEL: "Administrative",
ORDER: "3",
DEF_VALUE: "0",
LINK_LABEL: ""
},
{
CODE: "TOPIC",
LABEL: "NDF",
ORDER: "1",
DEF_VALUE: "0",
LINK_LABEL: "Administrative"
},
{
CODE: "TOPIC",
LABEL: "Report",
ORDER: "2",
DEF_VALUE: "1",
LINK_LABEL: "Administrative"
},
{
CODE: "TOPIC",
LABEL: "Other",
ORDER: "3",
DEF_VALUE: "0",
LINK_LABEL: "Administrative"
}, ...
]
我正在尝试映射并获取此列表
NSURL *baseUrl = [NSURL URLWithString: @"http://my_server"];
NSString *objName = @"MyEntity";
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
[RKManagedObjectStore setDefaultStore:managedObjectStore];
[managedObjectStore createPersistentStoreCoordinator];
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL: baseUrl];
RKEntityMapping *objMap = [RKEntityMapping mappingForEntityForName:objName inManagedObjectStore:managedObjectStore];
[objMap addAttributeMappingsFromDictionary: @{
@"CODE": @"code",
@"LABEL": @"label",
@"ORDER": @"order",
@"DEF_VALUE": @"def_value",
@"LINK_LABEL": @"link_label",
}];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:objMap pathPattern:nil keyPath:nil statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[objectManager addResponseDescriptor:responseDescriptor];
[objectManager getObjectsAtPath:objName parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"ok");
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"ko");
}];
它给了我这个错误
我restkit.network:RKHTTPRequestOperation.m:185 GET (200 OK)CoreData:错误: 由于未捕获的异常'NSUnknownKeyException',
'http://my_server/MyEntity'
无法在NSManagedObject类'MyEntity'上调用指定的初始化程序终止应用程序,原因: '[valueForUndefinedKey:]:实体(null) 与键“link_label”的键值编码不兼容。
我在 2 或 3 个 SO 问题上看到了这个错误,但每个问题都有不同的问题,而且似乎不是我的问题。
有人可以帮我调试吗?