title: How to create an instance of a class from a String in Swift
body: <p>I have tried creating an instance of a class using a string in numerous ways with none of them working <strong>in Swift 3</strong>.</p>
  
  <p><strong>Below are pre-Swift 3 solutions I have tried that are not working</strong></p>
  
  <p><strong>- Making class an objective-c class</strong></p>
  
  <pre><code>@objc(customClass)
  class customClass {
      ...
  }
  
  //Error here: cannot convert value of type 'AnyClass?' to expected argument type 'customClass'
  let c: customClass = NSClassFromString("customClass")
  </code></pre>
  
  <p><strong>- Specifying class using NSString value (both with and without using @objc attribute)</strong></p>
  
  <pre><code>@objc(customClass)
  class customClass {
      ...
  }
  
  //Error here: cannot convert value of type 'String' to expected argument type 'AnyClass' (aka 'AnyObject.Type')
  var className = NSStringFromClass("customClass")
  
  let c: customClass = NSClassFromString(className)
  </code></pre>
  
  <p>I'm not doing something right but have not found any solutions online.</p>
  
  <p><em>How do I create an instance of a class using a string in Swift 3?</em></p>