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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:55:48+00:00 2026-06-02T20:55:48+00:00

I want to have an array that is accessible throughout my Objective-C project whose

  • 0

I want to have an array that is accessible throughout my Objective-C project whose contents I can change where necessary. My problem is that when I call the array from a different class I always get null, and that’s not what I want.

In my .h file I have

@interface MainScreen2 : UIViewController
@property (nonatomic, strong) NSMutableArray *Judith;

and in the viewDidLoad function on the .m file I have:

@interface MainScreen2 ()

@end

@implementation MainScreen2
@synthesize Judith;


- (void)viewDidLoad
{
   self.Judith = [[NSMutableArray alloc]     initWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9", nil];                                                    
    [super viewDidLoad];
}

this is fine.

In a separate class I have:

#import "MainScreen2.h"

@interface NewGame ()
@end

- (void)viewDidLoad
{
    MainScreen2 *testJudith;

    NSMutableArray *testJudithArray = [[NSMutableArray alloc]init];
    testJudithArray = [testJudith.Judith mutableCopy];
    NSLog(@"Jud test: %@", [testJudith.Judith objectAtIndex:1]);
}

and the NSLog returns null for this point. Is this because when I am calling the Judith array from the MainScreen.h file it is empty at this point because it is not yet loaded?

If so, can anyone help me with where I should be putting the array so when I call it I retain it’s original contents?


EDIT: 30 Apr

Using a combination of the suggestions kindly put on this page I have now sorted out the problem and it now works.

I changed the code to the following:

- (void)viewDidLoad
{
MainScreen2 *testJudith = [[MainScreen2 alloc]init];
[testJudith viewDidLoad];
NSString *test = [testJudith.Judith objectAtIndex:1];
NSLog(@"Jud test: %@", test);
}

thanks to all that contributed to the forum post!

  • 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-02T20:55:49+00:00Added an answer on June 2, 2026 at 8:55 pm

    viewDidLoad is not the same as init…you either move the allocation of the NSArray in init or you call [testJudith viewDidLoad];

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

Sidebar

Related Questions

I have an array that I want to sort based on the value of
I have an array that I want on multiple pages, so I made it
I have an array that looks like $numbers = array('first', 'second', 'third'); I want
I have an associative array that I want to display using TileList. However, it
I have one array. I want that array to retain its value between function
I have an array of strings that I want to use for button titles
I have an multi-dimensional array that I want to send to a PHP script
I want to uapdate a table field with an array.That means i have a
I have two array and three button in segment control i want that when
I have this array, that I want to parse into javascript. $offerText[] = (

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.