Hi Guys!
So I've been doing a lot of reading. And I have been able to finally declare an extern MutableArray and access it from different Views. I have two views: 1) Testing View Controller 2) Test2
I declare the array as follows: TestingViewController.h
extern NSMutableArray *myArray;
#import <UIKit/UIKit.h>
@interface TestingViewController : UIViewController {
}
I initialize the array when the TestingViewController Loads. Then I can add Objects to it from Test 2 as Follows: Test2.m
#import "Test2.h"
NSMutableArray *myArray;
@implementation Test2
-(IBAction)addToArray{
[myArray addObject:@"Hot like Mexico"];
NSLog(@"Object was added to Array! Count: %d",[myArray count]);
}
It seems to be working from both Views. The count and Objects are consistant even while switching.
What I want to know is, what is wrong with this? I know a lot of experienced programmers hate global variables, but the only way I've gotten it to work is like above and through the AppDelegate (Don't want to do it that way). Just trying to be more efficient with adding and manipulating arrays from multiple Views.
Thank you guys!