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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:24:30+00:00 2026-06-03T06:24:30+00:00

am trying to add an array i get from NSURL into an array using

  • 0

am trying to add an array i get from NSURL into an array using for loop:

(int i = 0; i < 10; i++) 

to make it 2 dimensional array. Keep getting error on NSRangeException. It can only insertObject or addObject at index[0] and when ‘i’ increase to 1, it throws an error. It can only mean that its not adding but overwriting so when it overwrites the second time and i = 1, it throws the error. How do i add more instead of overwriting the initialized 2 dimensional arrays?

- (void)qBlock{
    for (int i = 0; i < 10; i++) {
        NSURL *url = [NSURL URLWithString:@"http://somefiles.php"];
        NSError *error;
        NSStringEncoding encoding;
        NSString *response = [[NSString alloc] initWithContentsOfURL:url 
                                                        usedEncoding:&encoding 
                                                               error:&error];
        if (response) {

            const char *convert = [response UTF8String];
            NSString *responseString = [NSString stringWithUTF8String:convert];
            NSMutableArray *sample = [responseString JSONValue];

            block = [[NSMutableArray alloc]init];
        [block insertObject:sample atIndex:i];
        }


    else {
        UIAlertView *alert1 = [[UIAlertView alloc]initWithTitle:@"ALERT" message:@"Internet Connection cannot be established." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert1 show];
    }
}
//Calling 10 blocks of codes
for (id obj in block) {
    NSLog(@"%@",obj);
}
  • 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-03T06:24:32+00:00Added an answer on June 3, 2026 at 6:24 am

    This:

            block = [[NSMutableArray alloc]init];
        [block insertObject:sample atIndex:i];
    

    Is replacing the entire block array with an empty array on each iteration through the for loop.

    Move your block array initialization outside of the for loop.

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

Sidebar

Related Questions

In Python, I'm trying to add elements from an array into a string using
I'm getting the following error when trying to add some data from myXml.xml to
I am trying a add data to an array using a while loop but
I am trying to add the results from the while loop into an xml
I'm trying to add values from array to DB, have tried many variuos examples
Trying to add a class object into a List using reflection, but when invoking
Im trying to add objects to an array by using push. I have a
I'm trying to add some functionality from a plugin I have made into a
I am trying to make an asynchronous request to get some data from my
Am trying to make a get request from javascript, with a function called geturl.

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.