Restats 0.20을 사용하여 오브젝트를 코어 데이터에 맵핑하고 저장합니다. 기본 매핑의 경우 잘 작동하지만 중첩 된 동적 매핑의 경우에는 작동하지 않습니다.Restkit 0.20 Dynamic Nested Mapping
//create entity mapping
RKEntityMapping *objectMapping = [RKEntityMapping mappingForEntityForName:@"Action"
inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
//create dynamic mapping
RKDynamicMapping *dynamicMapping = [RKDynamicMapping new];
//dressMapping and wardrobeMapping predefined mappings, they work well when mapping the wardobe and dress alone.
[dynamicMapping setObjectMappingForRepresentationBlock:^RKObjectMapping *(id representation) {
if ([[representation valueForKey:@"content_type"] isEqualToString:@"wardrobe"]) {
return wardrobeMapping;
} else if ([[representation valueForKey:@"content_type"] isEqualToString:@"dress"]) {
return dressMapping;
}
return nil;
}];
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"target" toKeyPath:@"target" withMapping:dynamicMapping]];
//maps actor
[objectMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"actor" toKeyPath:@"actor" withMapping:actorMapping]];
그리고 마지막으로, 내가 응답 디스크립터로 objectMapping 등록 :
RKResponseDescriptor *responseDescriptor =
[RKResponseDescriptor responseDescriptorWithMapping:objectMapping
pathPattern:nil
keyPath:nil
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
[[RKObjectManager sharedManager] addResponseDescriptor:responseDescriptor];
이 '아무튼
[
{
"actor": {
"id": 7,
"first_name": "Murat",
"last_name": "Akbal"
},
"target": {
"content_type": "dress",
"type": {
"id": 1,
"name": "leggings",
"kind": "bottom"
},
"style": {
"id": 1,
"name": "sport"
},
"full_name": "Murat - sport leggings",
"id": 19,
}
},
{
"actor": {
"id": 7,
"first_name": "Murat",
"last_name": "Akbal"
},
"target": {
"content_type": "wardrobe",
"style": {
"id": 1,
"name": "sport"
},
"id": 38,
"season": "spring",
"name": "asdasd"
}
}
]
내가 응답을지도하는 엔티티 매핑 다음을 사용 : 이것은 내 예를 들어 응답이다 예제 응답을 위해 작동하지 않으면 다음 오류가 발생합니다.
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Wardrobe 0x110e1a90> valueForUndefinedKey:]: the entity Wardrobe is not key value coding-compliant for the key "type".'
옷장에는 존재하지 않지만 입을 수있는 "type"키를 묻습니다. 여하튼 드레스 맵핑으로 옷장을 매핑하려고합니다. 그 문제에 대해 알고 있습니까?
fyi, coredata의 대상 유형이 변형 가능합니다.
옷장과 드레스 맵핑을 표시 할 수 있습니까? 또한 매핑에 대한 추적 로깅을 설정했습니다. RKLogConfigureByName ("RestKit/ObjectMapping", RKLogLevelTrace); – Wain