I am parsing some rss feeds from a site and when my code reaches the method of parser foundCharacters the application closes with an exc_bad_access error. The strange thing is that when i run my app in the simulator the app runs with no problem. This is my parse code :
#pragma mark NSXMLParser delegate
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:@"item"]) {
[item setObject:title forKey:@"title"];
[item setObject:link forKey:@"link"];
[feeds addObject:[item copy]];
}
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
element = elementName;
if ([element isEqualToString:@"item"]) {
item = [[NSMutableDictionary alloc] init];
title = [[NSMutableString alloc] init];
link = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)strings {
if ([element isEqualToString:@"title"]) {
[title appendString:strings];
} else if ([element isEqualToString:@"link"]) {
[link appendString:strings];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self.tableView reloadData];
}
My error is showing up when it reaches the first line of :
if ([element isEqualToString:@"title"]) {
[title appendString:strings];
} else if ([element isEqualToString:@"link"]) {
[link appendString:strings];
}
When i try to change those lines with for example :
[title appendString:strings];
it runs perfectly with the main difference that i get no link to enter the rss feed. In other words the problem seems to be when checking if element is equal to string @"title". Thank you.
No comments:
Post a Comment