美文网首页
Swift3.0 反射代码加载主类控制器

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

作者: hibear | 来源:发表于2016-11-07 10:32 被阅读0次

    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
    }
    

    }

    相关文章

      网友评论

          本文标题:Swift3.0 反射代码加载主类控制器

          本文链接:https://www.haomeiwen.com/subject/dlhnuttx.html