I am new in Objective-C and I am trying to create a singleton class based on Apple's documentation.
+ (MyGizmoClass*)sharedManager
{
if (sharedGizmoManager == nil) {
sharedGizmoManager = [[super allocWithZone:NULL] init];
}
return sharedGizmoManager;
}
+ (id)allocWithZone:(NSZone *)zone
{
return [[self sharedManager] retain];
}
In this code sharedManager is a static method which will check if object of this class is present. If so it will return the previous created object, otherwise it create a new one.
I have some questions:
If
sharedManageris static, how can it to accesssuper?When I print
[super class]why does it give the current class name?Why does
[[super allocWithZone:NULL] init]is return the current class object?If
superis equal toselfhere than why its not calling current class'sallocWithZone:(NSZone *)zone?