title: Instantiate Class Programmatically in iOS
body: <p>I am working a big iOS project, the design is not a nice as I would like it to be, but I must stick to it. (life can be a bitch sometimes).</p>
  
  <p>The thing is that we have a Library that basically let's you browse a catalog. You have a filter, where you specify a certain search criteria, and you are presented with a list were you can press on the items that you are interested. When you press an item, you can see a more detailed description of it.</p>
  
  <p>The company were a work for, sells this same software to many different companies that have different catalogs. The idea is that the Library has all the main functionality, and the project that use it, might in some way extend or completely override some of the given interfaces.</p>
  
  <p>To give you an example, imagine my library has 2 classes that manages 2 views. They would be "FilterViewController" and "DetailsViewControllers". In some place of the code this classes gets instantiated. It would look something like this</p>
  
  <p><img src="https://i.stack.imgur.com/FxOtK.jpg" alt="Class diagram schema"></p>
  
  <p>My approach is something like this:</p>
  
  <p><strong>ProjectA side</strong> </p>
  
  <pre><code>// Here I configure the library
  Library.FilterViewClass = ProjectAFilterViewController;
  Library.DetailsViewClass = ProjectADetailViewController;
  </code></pre>
  
  <p><strong>ProjectB side</strong> </p>
  
  <pre><code>Library.FilterViewClass = ProjectBFilterViewController;
  Library.DetailsViewClass = nil;
  </code></pre>
  
  <p><strong>Library side</strong></p>
  
  <pre><code>// Did the user configure the library?
  if(self.FilterViewClass == nil){
      // I alloc the default ViewController
      myFilterViewController = [[FilterViewController alloc] init]; 
  }else{
      // Here I would like to alloc the custom ViewController
      myFilterViewController = [[Library.FilterViewClass alloc] init]; // DaProblem!
  }
  </code></pre>
  
  <p>The problem with that approach is that I actually don't know if it's possible to instantiate object programmatically. Or at least I don't know how. Maybe I am using the wrong approach, some direction would be appreciated. Txs in advance!</p>