I need some clarification regarding the singleton object implementation in Objective C. I have implemented the following code for the singleton object ..
static MyClass *instance = nil;
+(MyClass *)getInstance
{
@synchronised(self)
{
if(instance == nil)
{
instance = [[self alloc] init];
}
}
return instance;
}
-(void)dealloc
{
[instance release];
[super dealloc];
}
Does the singleton object requires @synchronised block ???
I have custom defined constructor in my class as follows:
-(id)initWithDefault ..
Does the following line of code creates an issue while allocating for instance
instance = [[self alloc] initWithDefault];
awaiting for your response.