I’m trying to map the items of the RSS feeds. The RKObjectRequestOperation returns the exact number of objects but the attributes values are nil. Following is my code
NSURL *requestURL = [NSURL URLWithString:@"http://sports.espn.go.com/espn/rss/nfl/news"];
[RKMIMETypeSerialization registerClass:[RKXMLReaderSerialization class] forMIMEType:@"application/rss+xml"];
RKObjectMapping *rssFeedObjectMapping = [RKObjectMapping mappingForClass:[SBRssFeed class]];
[rssFeedObjectMapping addAttributeMappingsFromDictionary:@{
@"title" : @"title",
@"link" : @"link"
}];
RKResponseDescriptor *rssFeedResponseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:rssFeedObjectMapping
pathPattern:nil
keyPath:@"rss.channel.item"
statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
RKObjectRequestOperation *requestOperation = [[RKObjectRequestOperation alloc]initWithRequest:[NSURLRequest requestWithURL:requestURL]
responseDescriptors:@[rssFeedResponseDescriptor]];
[requestOperation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
_datasourceArray = mappingResult.array;
NSLog(@"Count %d", _datasourceArray.count);
[self.tableView reloadData];
}
failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"Error %@", error);
}];
[requestOperation start];
Is there something that I missed?
I figured out the problem. The problem was regarding to the
XMLReaderclass associated withRKXMLReaderSerialization. TheRKObjectMappingclass failed to map the dictionary’s keys with object’s properties. The reason was the output dictionary onXMLReader.As in the above response, each tag is associated with a dictionary, which in turn has ‘text’ as a key.
So I changed the object mapping to
This solved my problem.