title: Object initialization sequence in Objective-C
body: <p>The Cocoa framework has a convention to always call <code>self = [super init]</code> in the <code>init</code> method of an inherited class, because <code>[super init]</code> may return a new instance.</p>
  
  <p>What will happen if I do this?</p>
  
  <pre><code>@interface MyClass : NSObject /* or any other class */ {
      int ivar_;
  }
  @end
  
  @implementation MyClass
  
  - (id)init {
      ivar_ = 12345;
  
      if ((self = [super init])) {
          NSLog(@"ivar_'s value is %d", ivar_);
      }
      return self;
  }
  
  @end
  </code></pre>
  
  <p>In the case when <code>[super init]</code> returns a new instance, what will I see in the console? <code>ivar_'s value is 0</code>?</p>
  
  <p>I can't think of a way to check this myself, because I don't know which class may return a new instance from its <code>init</code> method. Also, can't seem to find explicit clarification for this scenario in the docs.</p>
  
  <p>Could anyone help me out? Thanks!</p>