【发布时间】:2014-07-03 14:07:16
【问题描述】:
我正在学习 Objective-C 并做一些个人项目应用程序。
我正在解析新闻提要并在表格视图中显示,一切正常。 但是每次我打开应用程序时,我都必须再次加载整个提要,并再次加载所有新闻。
我想知道,将这些新闻保存在本地存储中的最佳方法是什么,每次我打开应用程序时,只需检查提要以查看是否有新新闻并补充本地存储,这样我就可以填写只有本地保存新闻的tableview?
现在我正在使用 RaptureXML 来遍历项目并这样做:
-(void)fetchRssWithURL:(NSURL*)url complete:(RSSLoaderCompleteBlock)c{
dispatch_async(kBgQueue, ^{
RXMLElement *rss = [RXMLElement elementFromURL: url];
RXMLElement* title = [[rss child:@"channel"] child:@"title"];
NSArray* items = [[rss child:@"channel"] children:@"item"];
NSMutableArray* result = [NSMutableArray arrayWithCapacity:items.count];
cachedImages = [[NSMutableArray alloc] init];
if(items) {
for (RXMLElement *e in items) {
RSSItem* item = [[RSSItem alloc] init];
item.title = [[e child:@"title"] text];
item.description = [[e child:@"description"] text];
item.link = [NSURL URLWithString: [[e child:@"link"] text]];
item.content = [[e child:@"encoded"] text];
[result addObject: item];
}
}
c([title text], result);
});
}
【问题讨论】:
标签: ios objective-c xcode xml-parsing feed