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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:56:55+00:00 2026-06-18T09:56:55+00:00

I am back again and this will be my second question of the day.

  • 0

I am back again and this will be my second question of the day.

Anyways, I am using NSJSONSerialization to parse a data from my website. The data is in array format so I am using NSMutableArray. The problem is, I can’t access the data stored in NSMutableArray from different view controllers.

FirstView.h

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController

@property (nonatomic, strong) NSMutableArray *firstViewControllerArray;

@end

FirstView.m

- (void)ViewDidLoad
{
    [super viewDidLoad];

    NSURL *url = [NSURL URLWithString:@"http://j4hm.t15.org/ios/jsonnews.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    NSOperationQueue *queue = [[NSOperationQueue alloc]init];

    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
            self.firstViewControllerArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
    }];

    [self loadArray];
}

- (void)loadArray
{
    NSMutableArray *array = [NSMutableArray arrayWithArray:[self firstViewControllerArray]];

    //I also tried codes below, but it still won't work.
    //[[NSMutableArray alloc] initWithArray:[self firstViewControllerArray]];
    //[NSMutableArray arrayWithArray:[self.firstViewControllerArray mutableCopy]];

    NSLog(@"First: %@",array);

    SecondViewController *secondViewController = [[SecondViewController alloc] init];
    [secondViewController setSecondViewControllerArray:array];
    [[self navigationController] pushViewController:secondViewController animated:YES];
}

Second.h

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController

@property (nonatomic, strong) NSMutableArray *secondViewControllerArray;

@end

Second.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"Second: %@", [self secondViewControllerArray]);
}

Output

The NSLog(@"First: %@",array); will output the array hence it won’t be passing the SecondViewController a (null) value of the array.

However, NSLog(@"Second: %@", [self secondViewControllerArray]); will output (null). Am I missing something?

  • 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-18T09:56:56+00:00Added an answer on June 18, 2026 at 9:56 am

    I don’t believe your download is completing before you push your new view controller onto the stack, and also set that view controller’s array property. Right now, you’re calling -loadArray right after you tell NSURLConnection to download data asynchronously. This download is going to finish long after you try to access the array property.

    Try move the call to -loadArray within the asynchronous completion block (as seen below). Since this block is called when the download completes, you should have your data when you push the second view controller.

    [NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
            self.firstViewControllerArray = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
    
            dispatch_async(dispatch_get_main_queue(), ^{
    
                [self loadArray];
    
            });
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

back again with some more SQLAlchemy shenanigans. Let me step through this. My table
Back again with a javascript question within sharepoint. I would like to hide a
again a total newbie question from me about Haskell, and Leskah. (First, a subjective
I'm back again ... already. As the second part to my program, I need
I am trying to convert a Date to String and then back again to
I am back with a problem again (please cooperate with my silly questions, i
I'm back. Again. :3 Right now, I'm working on my RPG project (just for
This is a two part question. The first is a specific question about DataSets
This question has been asked before but in a slightly different way and I
Context: Building an app that populates a table that takes in data from a

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.