super allocWithZone having some doubts in singleton class concept

Viewed 1663

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:

  1. If sharedManager is static, how can it to access super?

  2. When I print [super class] why does it give the current class name?

  3. Why does [[super allocWithZone:NULL] init] is return the current class object?

  4. If super is equal to self here than why its not calling current class's allocWithZone:(NSZone *)zone?

3 Answers
Related