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