Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9239057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:54:00+00:00 2026-06-18T07:54:00+00:00

iOS beginner here. I’m trying to create an RSS reader for a news website,

  • 0

iOS beginner here. I’m trying to create an RSS reader for a news website, the RSS parser is in working order but it gives the exception EXC_BAD_ACCESS (code=2 address=0xc) if it’s compiled with ARC enabled.

Here’s how I call the parser: (in my view controller)

NSMutableArray* articleListMainPage;

- (void)viewDidLoad
{
    NSURL *mainFeed = [[NSURL alloc]initWithString:@"http://my.domain.com/rss.xml"];
    NSXMLParser *nsXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:mainFeed];
    NewsParser *myparser = [[NewsParser alloc] initNewsParser];
    [nsXmlParser setDelegate:myparser];

    if ([nsXmlParser parse]) {
        NSLog(@"Parsed article count : %i", [myparser.articles count]);
        articleListMainPage = [myparser.articles copy];
    } else {
        NSLog(@"Error parsing document!");
    }
    nsXmlParser = nil;
    mainFeed = nil;
    myparser = nil; // This line throws the exception.

    [super viewDidLoad];
}

and here’s the parser itself:

// NewsParser.m
#import "NewsParser.h"
#import "RSSEntry.h"

@implementation NewsParser

@synthesize article, articles, currValue;

- (NewsParser *) initNewsParser
{
    if (self = [super init]) return self; else return nil;
}

- (void)parser:(NSXMLParser *)parser
    didStartElement:(NSString *)elementName
    namespaceURI:(NSString *)namespaceURI
    qualifiedName:(NSString *)qualifiedName
    attributes:(NSDictionary *)attributeDict {

    if ([elementName isEqualToString:@"channel"]) {
        self.articles = [[NSMutableArray alloc] init];
    }
    if ([elementName isEqualToString:@"item"]) {
        self.article = [[ArticleEntry alloc] init];
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if (!currValue) {
        self.currValue = [[NSMutableString alloc] initWithString:string];
    } else {
        [self.currValue appendString:string];
    }
}

- (void)parser:(NSXMLParser *)parser
    didEndElement:(NSString *)elementName
     namespaceURI:(NSString *)namespaceURI
    qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"channel"]) {
        return;
    }

    if ([elementName isEqualToString:@"item"]) {
        [self.articles addObject:self.article];
        self.article = nil;
    } else {
        if ([[NSArray arrayWithObjects:@"title",@"link",@"description",nil] containsObject:elementName])
             [self.article setValue:self.currValue forKey:elementName];
    }
    self.currValue = nil;
}

@end

//NewsParser.h

#import <Foundation/Foundation.h>
#import "RSSEntry.h"

@interface NewsParser : NSXMLParser <NSXMLParserDelegate> {
    NSMutableString *currValue;
    NSMutableArray *articles;
    ArticleEntry *article;
}
- (NewsParser *) initNewsParser;
@property (nonatomic,retain) ArticleEntry *article;
@property (nonatomic,retain) NSMutableArray *articles;
@property (nonatomic,retain) NSMutableString *currValue;
@end

.. and the class I use for storing the RSS entries.

//RSSEntry.h
#import <Foundation/Foundation.h>

@interface ArticleEntry : NSObject {
    NSString *title;
    NSString *link;
    NSString *description;
}

@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *link;
@property (nonatomic, retain) NSString *description;

- (id)initNewArticle:(NSString*)_title url:(NSString*)_link description:(NSString*)_desc;

@end

//RSSEntry.m

#import "RSSEntry.h"

@implementation ArticleEntry
@synthesize title,link,description;
- (id)initNewArticle:(NSString *)_title url:(NSString *)_link description:(NSString *)_desc
{
    if ((self = [super init])) {
        title = [_title copy];
        link = [_link copy];
        description = [_desc copy];
        return self;
    }
    else return nil;
}
@end

Like I said, it works fine without ARC, but I want to know if I’m doing something that I shouldn’t be doing (e.g retaining something that I shouldn’t or not properly releasing something/overreleasing something) in the code.

Thanks for your time..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T07:54:01+00:00Added an answer on June 18, 2026 at 7:54 am

    So one issue here is that you declared NewsParser to be a subclass of NSXMLParser, which it shouldn’t be. It should be a subclass of NSObject (or something else appropriate)

    So in NewsParser.h, try this:

    @interface NewsParser : NSObject <NSXMLParserDelegate>
    

    BTW, you do have memory leaks there without ARC. The analyzer can help you fix those, if you intend to compile this code again without ARC. With or without ARC, there is no garbage collector here (it sounds as if you are counting on one?)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

iOS beginner here. I'm trying to build the Facebook Demo App but I keep
Beginner iOS dev here. I have a problem in my array. Im making an
I am a beginner to the iOS app development and working on a sample
I'm a beginner to the iOS development, and I'm trying to display an image
iOS beginner here. I'm using the following code to save my facebook accessToken and
I am a beginner in iOS development.We are trying to develop an application in
I'm a beginner in obj-C for iOS platform and am trying to build a
iOS beginner here. I am implementing SSO in my iOS app. I've created a
iOS beginner here. I have the following code: [facebook authorize:nil delegate:self]; NSString *string1=[facebook accessToken];
I'm a beginner in IOS but I need to show a video when the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.