我有一個管理對象MyEntity
,我在整個應用程序中使用時沒有任何問題。RestKit - 非密鑰值編碼兼容
@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
我有一個Web服務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");
}];
它給我這個錯誤
I restkit.network:RKHTTPRequestOperation.m:185 GET
'http://my_server/MyEntity'
(200 OK) CoreData: error: Failed to call designated initializer on NSManagedObject class 'MyEntity'
Terminating app due to uncaught exception 'NSUnknownKeyException', reason:
'[ valueForUndefinedKey:]: the entity (null) is not key value coding-compliant for the key "link_label".'
我看到這個錯誤或者2或3個SO問題,但每個問題都有不同的問題,而且看起來不是我的問題。
有人可以幫我調試嗎?
早期的錯誤,'未能呼籲NSManagedObject類指定初始化'MyEntity'是一個更直接的問題,可能是鍵值編碼例外的原因。 –