i am trying to devlope one RSSFeed application from http://www.raywenderlich.com/2636/how-t ... p-tutorial. everything was going well till this error occurs. i have checked everything in tutorial code but couldn't find anything. i have copied the code as it is. i have stuck here & wanted to get rid off it so i can go further & work get done. i am putting the piece of code below.even i have marked where error occurs. please anyone can help me with it. thnx in advance
Code:
// RootViewController.m
// RSSFun
#import "GDataXMLNode.h"
#import "GDataXMLElement-Extras.h"
#import "ASIHTTPRequest.h"
#import "RSSEntry.h"
#import "RootViewController.h"
@implementation RootViewController
@synthesize feeds = _feeds;
@synthesize queue = _queue;
@synthesize allEntries = _allEntries;
- (void)refresh {
for (NSString *feed in _feeds) {
NSURL *url = [NSURL URLWithString:feed];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[_queue addOperation:request];
}
}
- (void)addRows {
RSSEntry *entry1 = [[[RSSEntry alloc] initWithBlogTitle:@"1"
articleTitle:@"1"
articleUrl:@"1"
articleDate:[NSDate date]] autorelease];
RSSEntry *entry2 = [[[RSSEntry alloc] initWithBlogTitle:@"2"
articleTitle:@"2"
articleUrl:@"2"
articleDate:[NSDate date]] autorelease];
RSSEntry *entry3 = [[[RSSEntry alloc] initWithBlogTitle:@"3"
articleTitle:@"3"
articleUrl:@"3"
articleDate:[NSDate date]] autorelease];
[_allEntries insertObject:entry1 atIndex:0];
[_allEntries insertObject:entry2 atIndex:0];
[_allEntries insertObject:entry3 atIndex:0];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.title = @"Feeds";
self.allEntries = [NSMutableArray array];
self.queue = [[[NSOperationQueue alloc] init] autorelease];
self.feeds = [NSArray arrayWithObjects:@"http://feeds.feedburner.com/RayWenderlich",
@"http://feeds.feedburner.com/vmwstudios",
@"http://idtypealittlefaster.blogspot.com/feeds/posts/default",
@"http://www.71squared.com/feed/",
@"http://cocoawithlove.com/feeds/posts/default",
@"http://feeds2.feedburner.com/brandontreb",
@"http://feeds.feedburner.com/CoryWilesBlog",
@"http://geekanddad.wordpress.com/feed/",
@"http://iphonedevelopment.blogspot.com/feeds/posts/default",
@"http://karnakgames.com/wp/feed/",
@"http://kwigbo.com/rss",
@"http://shawnsbits.com/feed/",
@"http://pocketcyclone.com/feed/",
@"http://www.alexcurylo.com/blog/feed/",
@"http://feeds.feedburner.com/maniacdev",
@"http://feeds.feedburner.com/macindie",
nil];
[self refresh];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release anything that can be recreated in viewDidLoad or on demand.
// e.g. self.myOutlet = nil;
}
- (void)requestFinished : (ASIHTTPRequest *)request {
//Error occurs here
[_queue addOperationWithBlock:^
{
NSError *error;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:[request responseData]
options:0 error:&error];
if (doc == nil) {
NSLog(@"Failed to parse %@", request.url);
} else {
NSMutableArray *entries = [NSMutableArray array];
[self parseFeed:doc.rootElement entries:entries];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
for (RSSEntry *entry in entries) {
int insertIdx = 0;
[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
}
}];
}
}];
}
- (void)requestFailed : (ASIHTTPRequest *)request {
NSError *error = [request error];
NSLog(@"Error: %@", error);
}
- (void)parseFeed : (GDataXMLElement *)rootElement entries : (NSMutableArray *)entries {
if ([rootElement.name compare:@"rss"] == NSOrderedSame) {
[self parseRss:rootElement entries:entries];
} else if ([rootElement.name compare:@"feed"] == NSOrderedSame) {
[self parseAtom:rootElement entries:entries];
} else {
NSLog(@"Unsupported root element: %@", rootElement.name);
}
}
- (void)parseRss : (GDataXMLElement *)rootElement entries : (NSMutableArray *)entries {
NSArray *channels = [rootElement elementsForName:@"channel"];
for (GDataXMLElement *channel in channels) {
NSString *blogTitle = [channel valueForChild:@"title"];
NSArray *items = [channel elementsForName:@"item"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = [item valueForChild:@"link"];
NSString *articleDateString = [item valueForChild:@"pubDate"];
NSDate *articleDate = nil;
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate] autorelease];
[entries addObject:entry];
}
}
}
- (void)parseAtom : (GDataXMLElement *)rootElement entries : (NSMutableArray *)entries {
NSString *blogTitle = [rootElement valueForChild:@"title"];
NSArray *items = [rootElement elementsForName:@"entry"];
for (GDataXMLElement *item in items) {
NSString *articleTitle = [item valueForChild:@"title"];
NSString *articleUrl = nil;
NSArray *links = [item elementsForName:@"link"];
for(GDataXMLElement *link in links) {
NSString *rel = [[link attributeForName:@"rel"] stringValue];
NSString *type = [[link attributeForName:@"type"] stringValue];
if ([rel compare:@"alternate"] == NSOrderedSame &&
[type compare:@"text/html"] == NSOrderedSame) {
articleUrl = [[link attributeForName:@"href"] stringValue];
}
}
NSString *articleDateString = [item valueForChild:@"updated"];
NSDate *articleDate = nil;
RSSEntry *entry = [[[RSSEntry alloc] initWithBlogTitle:blogTitle
articleTitle:articleTitle
articleUrl:articleUrl
articleDate:articleDate] autorelease];
[entries addObject:entry];
}
}
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView : (UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger)section {
return [_allEntries count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
RSSEntry *entry = [_allEntries objectAtIndex:indexPath.row];
NSDateFormatter * dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setTimeStyle:NSDateFormatterMediumStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *articleDateString = [dateFormatter stringFromDate:entry.articleDate];
cell.textLabel.text = entry.articleTitle;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@ - %@", articleDateString, entry.blogTitle];
return cell;
}
- (void)dealloc {
[super dealloc];
[_allEntries release];
_allEntries = nil;
[_queue release];
_queue = nil;
[_feeds release];
_feeds = nil;
}
@end
Last edited by a moderator: