I've reviewed (and tried) a bunch of the threads here regarding Singletons and NSMutableArrays. I'm new to Objective-C so please bear with me.
I simply want to create a few arrays that can be accessed from any view/.m file.
What is the best (or most concise) coding for a Singleton?
Below is what I have now and I get 1 warning at .m '@implementation' - "Incomplete implementation" 1 error at usage in a view .m file - "initializer element is not a compile-time constant"
This is the code I have now - my GlobalData.h file:
#import <Foundation/Foundation.h>
@interface GlobalData : NSObject {
NSMutableArray *listOfHeadings;
NSMutableArray *listOfItems1;
NSMutableArray *listOfItems2;
}
@property(nonatomic,retain)NSMutableArray *listOfHeadings;
@property(nonatomic,retain)NSMutableArray *listOfItems1;
@property(nonatomic,retain)NSMutableArray *listOfItems2;
+(GlobalData*)getInstance;
@end
My GlobalData.m file:
#import "GlobalData.h"
@implementation GlobalData
@synthesize listOfHeadings;
@synthesize listOfItems1;
@synthesize listOfItems2;
static GlobalData *instance=nil;
+(GlobalData *)getInstance
{
@synchronized(self)
{
if(instance==nil)
{
instance= [GlobalData new];
}
}
return instance;
}
@end
And in a view .m file (simplified):
#import GlobalData.h
GlobalData *globDat=[GlobalData getInstance]; //error occurs here
Can someone point out the trouble and if there's better coding, please enlighten me - thanks!
EDIT
Here's a few links I've tried to use:
Can i have a single NSMutableArray in my multiple views application?