Question

What would be the equivalent syntax of the following code for RestKit 0.20?

RKObjectMapping *atozMapping = [RKObjectMapping mappingForClass:[Atoz class]];
[atozMapping mapKeyPath:@"" toAttribute:@"city"];

RKObjectMapping *genreMapping = [RKObjectMapping mappingForClass:[Genres class]];
[genreMapping mapKeyPath:@"" toAttribute:@"genre"];

RKObjectMapping *stationSearchMapping = [RKObjectMapping mappingForClass:[StationSearchData class]];
[stationSearchMapping mapKeyPathsToAttributes:@"location", @"location", @"city", @"city", @"latitude", @"latitude", @"longitude", @"longitude", nil];
[stationSearchMapping mapKeyPath:@"browseatoz.atoz" toRelationship:@"browseAtozArray" withMapping:atozMapping];
[stationSearchMapping mapKeyPath:@"genres.genre" toRelationship:@"genreArray" withMapping:genreMapping];

[stationMapping mapRelationship:@"stationSearchData" withMapping:stationSearchMapping];
[stationManager.mappingProvider setMapping:stationSearchMapping forKeyPath:@"stationSearchData"];

Here's what I've tried, but it seems to not be loading the browseAtozArray (city is null) and genreArray (genre is null) correctly:

RKObjectMapping *atozMapping = [RKObjectMapping mappingForClass:[Atoz class]];
[atozMapping addAttributeMappingsFromDictionary:@{
                                                      @"": @"city",
                                                      }];

RKObjectMapping *genreMapping = [RKObjectMapping mappingForClass:[Genres class]];
[genreMapping addAttributeMappingsFromDictionary:@{
                                                  @"": @"genre",
                                                  }];

RKObjectMapping *stationSearchMapping = [RKObjectMapping mappingForClass:[StationSearchData class]];
[stationSearchMapping addAttributeMappingsFromDictionary:@{
                                                  @"location.text": @"location",
                                                  @"city.text": @"city",
                                                  @"latitude.text": @"latitude",
                                                  @"longitude.text": @"longitude"
                                                  }];
RKRelationshipMapping* relationShipatozMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"browseatoz.atoz" toKeyPath:@"browseAtozArray" withMapping:atozMapping];
[stationSearchMapping addPropertyMapping:relationShipatozMapping];
RKRelationshipMapping* relationShipGenresMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"genres.genre" toKeyPath:@"genreArray" withMapping:genreMapping];
[stationSearchMapping addPropertyMapping:relationShipGenresMapping];

[stationMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"stationSearchData" toKeyPath:@"stationSearchData" withMapping:stationSearchMapping]];

[stationManager addResponseDescriptor: [RKResponseDescriptor responseDescriptorWithMapping:stationSearchMapping method:RKRequestMethodGET pathPattern:nil keyPath:@"stationSearchData" statusCodes:[NSIndexSet indexSetWithIndex:200]]];

and here's the relevant XML:

<stationSearchData>
   <location>
  <![CDATA[ 79605 ]]>
 </location>
 <city>
  <![CDATA[ Abilene ]]>
 </city>
 <latitude>
  <![CDATA[ 32.43892288 ]]>
 </latitude>
 <longitude>
  <![CDATA[ -99.77902222 ]]>
 </longitude>
 <browseatoz>
  <atoz>
   <![CDATA[ Abilene ]]>
  </atoz>
  <atoz>
   <![CDATA[ Texas ]]>
  </atoz>
 </browseatoz>
 <genres>
  <genre>
   <![CDATA[ Rock ]]>
  </genre>
 </genres>
 <personalities/>
</stationSearchData>

Also, this question seems to be the same problem I'm having (except that it's solution is what I was using for the older version of RestKit, and does not work for 0.20): How to map XML textContent with RestKit?

Was it helpful?

Solution

I don't work with XML much but look at trying a nil key path mapping:

[genreMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"genre"]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top