Hi; I have create a SinglestonClass in my code but i have a problem. My variable are initialized in the -init method but when i call the singlestonClass these variable are re-initialize. Can you help me for create a single initialization for my variable? thanks.
@implementation SingletonController
@synthesize arrayPosition;
@synthesize arrayMovement;
@synthesize actualPosition;
@synthesize actualMove;
@synthesize stopThread;
+(SingletonController*)sharedSingletonController{
static SingletonController *sharedSingletonController;
@synchronized(self) {
if(!sharedSingletonController){
sharedSingletonController = [[SingletonController alloc]init];
}
}
return sharedSingletonController;
}
//I don't want a re-initialization for these variables
-(id)init{
self = [super init];
if (self != nil) {
arrayPosition = [[NSMutableArray alloc]init];
arrayMovement = [[NSMutableArray alloc]init];
actualPosition = [[Position alloc]init];
actualMove = [[Movement alloc]init];
stopThread = FALSE;
}
return self;
}
-(void) dealloc {
[super dealloc];
}
@end