我正在尝试映射 RSS 提要的项目。RKObjectRequestOperation 返回对象的确切数量,但属性值为 nil。以下是我的代码
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];
有什么我错过的吗?