Can I have one NSMutableArray in an application with multiple views?

I have a navigation based application that has several views. Is it possible to use one single NSMutableArray for the whole application? Can I add objects to this NSMutableArray in one view and then remove the object from the same NSMutableArray from another view? I tried

 myappAppDelegate *appDelegate = (myappAppDelegate *)[[UIApplication sharedApplication] delegate];

but it gives me null when I try to access the appDelegate array. If anyone can give me any idea or help link or tutrorial. Thanks in advance.

0
source share
4 answers

, , , / (singleton) . - :

//DataClass.h      

@interface DataClass : NSObject {    

NSMutableArray *arrGlobal;     

}    
@property(nonatomic,retain)NSMutableArray *arrGlobal;   
+(DataClass*)getInstance;    
@end  



//DataClass.m    
@implementation DataClass    
@synthesize arrGlobal;    
static DataClass *instance =nil;    
+(DataClass *)getInstance    
{    
    @synchronized(self)    
    {    
        if(instance==nil)    
        {    

            instance= [DataClass new];    
        }    
    }    
    return instance;    
}    

:

DataClass *obj=[DataClass getInstance];  
obj.arrGlobal = arrLocal; 

. Data.

+2
+2

AppDelegate , , , , , .

, appDelegate, , , ( ) myappDelegate, AppDelegate .

+1

Singleton

instance.arrGlobal = [[NSMutableArray alloc] init];

:

@synchronized(self)    
{    
    if(instance==nil)    
    {    

        instance= [DataClass new];
        instance.arrGlobal = [[NSMutableArray alloc] init];
    }    
}    
return instance;

, .

+1

All Articles