I followed a tutorial to implement Singleton and its working fine .Below is the code:
@implementation DKSingle
static DKSingle *dKSingle = nil;
+(id)dKSingleInstance{
if (!dKSingle) {
dKSingle = [[DKSingle alloc]init];
}
return dKSingle;
}
-(id)init{
if (!dKSingle) {
dKSingle = [super init];
}
return dKSingle;
}
@end
My question is dKSingle is a static variable, then how come it works inside the instant method init . Please help me to understand.