Swift3.0 反射代码加载主类控制器

2016-11-07  本文已影响0人  hibear

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
}

}

上一篇下一篇

猜你喜欢

热点阅读