title: What is the syntax and use of a factory method in Objective-C
body: <p>I have been searching the web trying to understand what factory methods are but I haven't found any simple example that shows a concrete example. One of the books I have briefly talks about them but it doesn't show an example nor gives an explanation of what they are "Class methods are commonly used as factory methods".</p>
  
  <p><strong>1- What is the syntax and use of a factory method in Objective-C?</strong> <a href="https://stackoverflow.com/questions/19450940/what-is-the-purpose-of-using-a-factory-method-in-objective-c-context">This</a> is the closest answer I found but when I tried the example in the comment maked as the answar I got a message saying that I couldn't call super. In this question I'm more concern about the syntax of the implementation of the factory method.</p>
  
  <p><strong>2- Are factory methods what are called constructors in other languages?</strong></p>
  
  <p><strong>3- How are factory methods compared to Singletons?</strong></p>
  
  <p>From Apple documentation:</p>
  
  <blockquote>
    <p>They combine allocation and initialization in one step and return the
    created object</p>
  </blockquote>
  
  <p>Is not what singleton does?</p>
  
  <p>In the following singleton example, can we say that the class method sharedData is a factory method?    </p>
  
  <p>.m File   </p>
  
  <pre><code>#import "SingletonModel.h"
  @implementation SingletonModel
  static SingletonModel *sharedData;
  
  - (id) init {
      if (self = [super init]) {
          // custom initialization
      }
      return self;
  }
  
   // is this a factory method?
  +(SingletonModel*) sharedData
  {
      if (!sharedData) {
          sharedData = [[SingletonModel alloc]init];
      }
      return sharedData;
  }
  @end
  </code></pre>