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 8661829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:35:33+00:00 2026-06-12T16:35:33+00:00

I’m trying to add elements of a specific name to an NSMutableArray, which I’m

  • 0

I’m trying to add elements of a specific name to an NSMutableArray, which I’m getting from an XML file. I’m after the element. The first NSLog here outputs correctly:

Found an element named: image with a value of: http://media.giantbomb.com/uploads/1/10353/2320941-untitledb_tiny.jpg

The second NSLog outputs correctly:

I'm about to try adding a game called Bayonetta 2 to the array

The third NSLog always tells me that there are zero entries in the array. I didn’t get any error on the [_listOfGameNames addObject: element]; line, so I have no idea why it’s not adding it to the array.

Any ideas for me? Here’s the code in full:

- (void) searchWithString: (NSString *)string {
    NSString *searchString = [NSString stringWithFormat: @"http://api.giantbomb.com/search/?api_key=MYKEY12345BLAHBLAH&resources=game&format=xml&query=%@", string];
    NSURL *searchURL = [NSURL URLWithString: searchString];
    parser = [[NSXMLParser alloc] initWithContentsOfURL: searchURL];
    [parser setDelegate:self];
    [parser parse];
    // NSLog(@"XMLParser just reached the end of its initWithString method. The string was %@",  searchURL);
    NSLog(@"There are %u elements in the List Of Game Names array", [_listOfGameNames count]);
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict {
    element = [NSMutableString string];
}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
    NSLog(@"Found an element named: %@ with a value of: %@", elementName, element);
    if ([elementName isEqualToString:@"name"]) {
        NSLog(@"I'm about to try adding a game called %@ to the array", element);
        [_listOfGameNames addObject: element];
        NSLog(@"I added an element to the array, making a total of %u", [_listOfGameNames count]);
    }
}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
    if(element == nil) element = [[NSMutableString alloc] init];
    [element appendString:string];
}
  • 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-12T16:35:34+00:00Added an answer on June 12, 2026 at 4:35 pm

    You need to init the array. and you can implement the Getter.

    -(NSMutableArray *) listOfGameNames
    {
        if(!_listOfGameNames){
            _listOfGameNames = [[NSMutableArray alloc] init];
        }
    
        return _listOfGameNames;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to select an H1 element which is the second-child in its group
I am trying to understand how to use SyndicationItem to display feed which is
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I'm parsing an XML file, the creators of it stuck in a bunch social

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.