내 코드에서 SinglestonClass를 만들었지 만 문제가 있습니다. My 변수는 -init 메서드에서 초기화되지만 singlestonClass를 호출하면이 변수가 다시 초기화됩니다. 변수에 대해 단일 초기화를 만들 수 있습니까? 덕분에 .객관적인 c의 싱글 톤 클래스
@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