2013-05-29 3 views
0

같은 유형의 중첩 된 객체를 어떻게 매핑 할 수 있습니까? 그것을 할 수동일한 유형의 중첩 된 객체를 다시 만들려면

+ (RKObjectMapping *)objectMapping { 
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]]; 
    [mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}]; 
    [mapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"nextEntries" 
                      toKeyPath:@"entries" 
                      withMapping:[Entry objectMapping]]]; 

    return mapping; 
} 

: 내가 같은 매핑으로 propertymapping를 추가하면

<entry location="l1"> 
    <entry location="l1.1"> 
     <entry location="l1.1.1"> 
     </entry> 
     <entry location="l1.1.2"> 
     </entry> 
    </entry> 
</entry> 

내가 무한 재귀를 얻을 : 나는 동일한 유형의 여러 객체를 포함 할 수 있습니다 개체를 사용하여 XML을 각 부모 객체의 배열에 하위 객체를 추가 하시겠습니까? 다음 코드 나를 위해 작동 :

// 편집

환호

나는 그것을 시도하지 않은

+ (RKObjectMapping *)objectMapping 
{ 
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]]; 
    [mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}]; 

    RKObjectMapping *innerMapping = [RKObjectMapping mappingForClass:[Entry class]]; 
    [innerMapping addAttributeMappingsFromDictionary:@{@"location": @"location"}]; 

    [mapping addPropertyMapping:[RKRelationshipMapping 
     relationshipMappingFromKeyPath:@"entry" 
     toKeyPath:@"entries" 
     withMapping:innerMapping]]; 

    return mapping; 
} 

답변

2

그래서 나는 그것이 작동하는지 알고 있지만이 시도하지 않습니다

+ (RKObjectMapping *)objectMapping 
{ 
    RKObjectMapping *mapping = [RKObjectMapping mappingForClass:[Entry class]]; 
    [mapping addAttributeMappingsFromDictionary:@{@"location": @"location"}]; 

    RKObjectMapping *innerMapping = [RKObjectMapping mappingForClass:[Entry class]]; 
    [innerMapping addAttributeMappingsFromDictionary:@{@"location": @"location"}]; 

    [mapping addPropertyMapping:[RKRelationshipMapping 
     relationshipMappingFromKeyPath:@"nextEntries" 
     toKeyPath:@"entries" 
     withMapping:innerMapping]]; 

    return mapping; 
} 

toKeyPath:@"entries"이 정확한지 확실하지 않은 경우 XML을 기준으로 toKeyPath:@"entry" 일 필요가 있습니다.

무한 재귀는 자신이 동일한 메소드 ([Entry objectMapping])를 호출했기 때문에 매핑과 아무 관련이 없습니다.

+0

많은 감사합니다. 작동합니다! – kampfgnu

+0

올바른 답을 수락하고 문제를 해결하는 데 도움을주십시오. 감사 :) – Wain

관련 문제