title: How to initialize Objective C class variable in init?
body: <p>In the <code>@interface</code>, I have this declaration:</p>
  
  <pre><code>@interface myClass {
     NSDictionary * myData;
  }
  
  @property (nonatomic, assign) NSDictionary * data;
  + (id) initWithData:(NSDictionary *)data;
  
  @end
  </code></pre>
  
  <p>In the <code>@implementation</code>, I have this code:</p>
  
  <pre><code>@implementation
  
  @synthesize data;
  
  + (id) initWithData:(NSDictionary *)freshData {
      self = [super init];
      if (self) {
          self-&gt;data = freshData;
      }
      return self;
  }
  
  @end
  </code></pre>
  
  <p>But I got error <code>Incomplete definition of type 'struct objc_class</code> on <code>self-&gt;data</code>.</p>
  
  <p>If I change it into <code>self.data</code>, I got error <code>Member reference type 'struct objc_class *' is a pointer; did you mean to use '-&gt;'?</code></p>
  
  <p>If I remove the <code>self</code>, I got error `Instance variable 'data' accessed in class method.'</p>
  
  <p>But if I change the method type from <code>+</code> (class method) to <code>-</code> (instance method), I cannot access the init.</p>
  
  <p>And I cannot fix this error by change the assignment from <code>data</code> to <code>myData</code> either.</p>
  
  <p>How should I make a constructor?</p>
  
  <p>The link that I have learned from (but not helping) are:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15951441/using-self-in-an-implementation">Using &#39;self&#39; in an @implementation</a></li>
  <li><a href="http://rypress.com/tutorials/objective-c/classes" rel="nofollow noreferrer">http://rypress.com/tutorials/objective-c/classes</a></li>
  </ul>