Swift3.0 反射代码加载主类控制器
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow()
window?.backgroundColor = UIColor.blue
let clsName = "微博demo.ViewController"
let cls = NSClassFromString(clsName) as? UIViewController.Type
let vc = cls?.init()
//let vc = ViewController()
window?.rootViewController = vc
window?.makeKeyAndVisible()
return true
}
}
网友评论