SOLVED-
Got it! The problem was that since I am creating the DoParsingStuff *parseThisUrl object in the viewDidLoad method, it's scope was only within that method. So after the method finished, the object got deallocated.
I changed it to an instance variable instead and now it works. It gives a different error but that it an entirely different issue.
Issue was:
I have been struggling with trying to integrate the mwfeedparser library in my app for parsing RSS and ATOM feeds. It throws a gives EXC_BAD_ACCESS error which I can't seem to troubleshoot.
//My Class looks like - My interface looks like:
#import <Foundation/Foundation.h>
#import "MWFeedParser.h"
#import "NSString+HTML.h"
@protocol ParseCompleted <NSObject>
-(void)parsedArray:(NSMutableArray *)parsedArray;
@end
@interface DoParsingStuff : NSObject<MWFeedParserDelegate>
@property (nonatomic,strong) NSMutableArray *parsedItems;
@property (nonatomic, strong) NSArray *itemsToDisplay;
@property (nonatomic,strong) MWFeedParser *feedParser;
@property (nonatomic,strong) NSURL *feedurl;
@property (nonatomic,strong) id <ParseCompleted> delegate;
-(id)initWithFeedURL:(NSURL *)url;
@end
//And Implementaion:
#import "DoParsingStuff.h"
@implementation DoParsingStuff
@synthesize parsedItems = _parsedItems;
@synthesize itemsToDisplay = _itemsToDisplay;
@synthesize feedParser = _feedParser;
@synthesize feedurl=_feedurl;
@synthesize delegate = _delegate;
-(id)initWithFeedURL:(NSURL *)url{
if(self = [super init]){
_feedurl=url;
_feedParser = [[MWFeedParser alloc] initWithFeedURL:_feedurl];
_feedParser.delegate=self;
_feedParser.feedParseType=ParseTypeFull;
_feedParser.connectionType=ConnectionTypeAsynchronously;
}
return self;
}
-(void)doParsing{
BOOL y = [_feedParser parse];
}
# pragma mark -
# pragma mark MWFeedParserDelegate
- (void)feedParserDidStart:(MWFeedParser *)parser {
//Just tells what url is being parsed e.g. http://www.wired.com/reviews/feeds/latestProductsRss
NSLog(@"Started Parsing: %@", parser.url);
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedInfo:(MWFeedInfo *)info {
//What is the Feed about e.g. "Product Reviews"
NSLog(@"Parsed Feed Info: “%@”", info.title);
//self.title = info.title;
}
- (void)feedParser:(MWFeedParser *)parser didParseFeedItem:(MWFeedItem *)item {
//Prints current element's title e.g. “An Arthropod for Your iDevices”
NSLog(@"Parsed Feed Item: “%@”", item.title);
if (item) [_parsedItems addObject:item];
}
- (void)feedParserDidFinish:(MWFeedParser *)parser {//This is where you can do your own stuff with the parsed items
NSLog(@"Finished Parsing%@", (parser.stopped ? @" (Stopped)" : @""));
[_delegate parsedArray:_parsedItems];
//[self updateTableWithParsedItems];
}
- (void)feedParser:(MWFeedParser *)parser didFailWithError:(NSError *)error {
NSLog(@"Finished Parsing With Error: %@", error);
if (_parsedItems.count == 0) {
//self.title = @"Failed"; // Show failed message in title
} else {
// Failed but some items parsed, so show and inform of error
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Parsing Incomplete" message:@"There was an error during the parsing of this feed. Not all of the feed items could parsed." delegate:nil cancelButtonTitle:@"Dismiss" otherButtonTitles:nil];
[alert show];
}
//[self updateTableWithParsedItems];
}
@end
//I am calling this from my main viewcontroller as such:
#import "DoParsingStuff.h"
@interface ViewController : UIViewController <ParseCompleted>
....
//And I have the following methods in my implementation:
DoParsingStuff *parseThisUrl = [[DoParsingStuff alloc] initWithFeedURL:[NSURL URLWithString:@"http://www.theverge.com/rss/index.xml"]];
parseThisUrl.delegate=self;
[parseThisUrl doParsing];
I have the method defined here as-
-(void)parsedArray:(NSMutableArray *)parsedArray{
NSLog(@"%@",parsedArray);
}
//I stepped through breakpoints-
When I try to go through the breakpoints, I see that everything goes fine till the very last [parseThisUrl doParsing]; in my delegate class. After that it starts showing me memory registers where I get lost.
I think it could be due to arc as I have disabled arc on the mwfeedparser files but am using arc in the above classes. If you need the entire project for this, let me know.
I tried it with NSZombies enabled and got a bit more info out of it:
-[DoParsingStuff respondsToSelector:]: message sent to deallocated instance 0x6a52480
I am not using release/autorelease/retain etc. in this class...but it is being used in the mwfeedparser library.