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

  • Home
  • SEARCH
  • 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 8946855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:36:20+00:00 2026-06-15T12:36:20+00:00

MasterViewController.h: #import <UIKit/UIKit.h> @interface MasterViewController : UITableViewController @property (nonatomic, strong) NSMutableArray *listOfBugs; MasterViewController.m: –

  • 0

MasterViewController.h:

#import <UIKit/UIKit.h>

@interface MasterViewController : UITableViewController

@property (nonatomic, strong) NSMutableArray *listOfBugs;

MasterViewController.m:

- (void)viewDidLoad
{
    [super viewDidLoad];
    _listOfBugs = [[NSMutableArray alloc]init];
}

...
...

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{
    ScaryBugDoc *bug = [self.bugs objectAtIndex:indexPath.row];
    [_listOfBugs addObject:bug];
}

In the above code I’ve created an array that holds objects with properties.
I want to access the objects inside the array from a different class and also add objects to the same array. I know I can create a new array from the same class like this:

ListOfBugsViewController.m:

#import "ListOfBugsViewController.h"
#import "MasterViewController.h"
MasterViewController *myClass = [[MasterViewController alloc]init];


    NSMutableArray *array = [myClass.listOfBugs....

But obviously that’s not what I’m looking for. I want to access the objects that are already inside the array and not to create a new array.

Edit: To make things a bit simpler, I have a few classes and only one array I’m adding objects to. All classes should be able to add objects to it and read previously added objects.
How can I access that same array from a class it wasn’t allocated and initialized in?

Thanks

  • 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-15T12:36:21+00:00Added an answer on June 15, 2026 at 12:36 pm

    Adding an object to an array from other class in fairly simple.

    Just see how…

    Base.m

    ...
    _baseArray=[[NSMutableArray alloc]init];
    [_baseArray addObject:@"Anoop"];
    [_baseArray addObject:@"kumar"];
    ...
    

    OtherClass.m

    Base *baseObj=[Base new];
    [baseObj.baseArray addObject:@"vaidya"];
    

    EDIT:

    As per our discussion

    - (void)awakeFromNib
    {
        [super awakeFromNib];
        [self createObjects];
    
    }
    
    - (void) createObjects
    {
        _listOfBugs=[[NSMutableArray alloc]init];
    
        [_listOfBugs addObject:@"Anoop"];
    
        NSLog(@"init done, %@",_listOfBugs);
    
    }
    
    
    - (id)init
    {
        self = [super init];    
        if (self) {
            [self createObjects];
        }
        return self;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my MasterViewController.h is as follows: @interface XYZMasterViewController : UITableViewController <NSFetchedResultsControllerDelegate, UIAlertViewDelegate> { NSMutableArray *array;
Can Anyone Tell me why the function is Not Calling Here Class MasterViewController.h @interface
I have a superclass of UIViewController - MasterViewController which declares a property called itemsViewController
How can i send an array from the masterViewController to the DetailViewController in a
I user Master-Detail created a project. On the MasterViewController , the table cell i
i am implementing a core data example in xcode 4.2 at insertMethod (in MasterViewController.m
I have implemented a MGSplitViewController where I have 6 rows in the masterviewcontroller and
When I transition from one view controller (let's call it MasterViewController ) to another
DetailViewController <-> MasterViewController <-> ViewController At the moment I solve my problem by having
I have a MasterViewController in a MAster Detail aplication showind data in a UITableView.

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.