Instantiate the object based on the class name. For example, create a ViewController instance based on a string of class names.
let controllerName = "SpainAppProto." + xibName // xibName is shaped like XXViewController
var classType: AnyObject.Type = NSClassFromString (controllerName)
var nsobjectype: UIViewController.Type = classType as UIViewController.Type
var viewController: UIViewController = nsobjectype (nibName: xibName, bundle: nil)
But when it is instantiated according to UIViewController.self, it needs to be converted slightly
var x: String = m.debugDescription // m is UIViewController.self
x = x.stringByReplacingOccurrencesOfString ("Optional (", withString: "")
x = x.stringByReplacingOccurrencesOfString (")", withString: "")
let anyClass: AnyClass = NSClassFromString (x)
let viewControllerClass: UIViewController.Type = anyClass as UIViewController.Type
let viewController = viewControllerClass ()
Swift syntax-Swift instantiates objects by class name