-1

RestKitObjectMapping Array off null objects

I want to map CapitalImage object in Capital images object property.

//------------------------ The mapping I try to 


  [RKMIMETypeSerialization registerClass:[RKNSJSONSerialization class]
                                   forMIMEType:@"text/html"];


    RKObjectMapping *CapitalImageMap = [RKObjectMapping mappingForClass:[CapitalImage class]];
    [CapitalImageMap addAttributeMappingsFromDictionary:@{
                                                     @"src":  @"src"
                                                     }];


    RKObjectMapping *CapitalMap = [RKObjectMapping mappingForClass:[Capital class]];
    [CapitalMap addAttributeMappingsFromDictionary:@{
                                                  @"name":  @"name",
                                                  @"text":  @"text"
                                                  }];

   [CapitalMap addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"images" toKeyPath:@"images" withMapping:CapitalImageMap]];

    NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful);
    RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:CapitalMap
                                                                                            method:RKRequestMethodAny
                                                                                       pathPattern:nil
                                                                                           keyPath:nil
                                                                                       statusCodes:statusCodes];

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.a10073.de4.dp10.ru/icapitals/capital.php"]];
    RKObjectRequestOperation *operation = [[RKObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
    [operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *result) {

        Capital *article = [result firstObject];
        NSLog(@"Mapped the article: %@ , %@", article.name,article.images.description);

    } failure:^(RKObjectRequestOperation *operation, NSError *error) { NSLog(@"Failed with error: %@", [error localizedDescription]); }];

    [operation start];

I get this result

2013-09-27 23:20:49.028 iCapitals v2[5099:c07] Mapped the article: London , (
    (null),
    (null),
    (null),

)

LOGS - http://www.a10073.de4.dp10.ru/icapitals/consoleresult.txt

Please check the code and tell what i do wrong, Thanks!!!

Imodeveloper
  • 394
  • 4
  • 13
  • 1
    Turn on trace logging for the mapping. What data type is `src` in `CapitalImageMap`? – Wain Sep 27 '13 at 20:53
  • This is result on console after adding RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelTrace); http://www.a10073.de4.dp10.ru/icapitals/consoleresult.txt – Imodeveloper Sep 27 '13 at 21:00

1 Answers1

0

Your mappings look correct. The log shows the mapping proceeding correctly. The issue appears to be with the CapitalImage class. Why is it giving a nil description? It could be that that is the only problem. So your log of the array is a list of nil, but the objects do exist.

Try logging the src of each objects. Are you seeing other issues? Did you implement the description method?

Wain
  • 118,658
  • 15
  • 128
  • 151