title: Singleton Class Strict Implementation in Objective-C
body: <p>I am trying to create a singleton class. While searching for related documents, I came across an <a href="https://developer.apple.com/legacy/library/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW32" rel="nofollow">Apple Document</a> that gives a strict implementation of a singleton. Where I found the following piece of code:</p>
  
  <pre><code>+ (MyGizmoClass*)sharedManager
  {
      if (sharedGizmoManager == nil) {
          sharedGizmoManager = [[super allocWithZone:NULL] init];
      }
      return sharedGizmoManager;
  }
  
  + (id)allocWithZone:(NSZone *)zone
  {
      return [[self sharedManager] retain];
  }
  </code></pre>
  
  <p>Can anyone tell me, why is it necessary to call <code>+allocWithZone:</code>?. Why does calling <code>+alloc</code> end up in a crash?</p>
  
  <p>Also we've overridden <code>+allocWithZone:</code>. Why so? Why cant we override <code>+alloc</code> instead?</p>
  
  <p>Thanks in advance.</p>