在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) // 依据String名字拿到控制器(添加项目名称,命名空间,不能有数字和特殊符号) // 返回的是AnyClass? 需要as?强转 // 控制器添加Type类型 let rootControl = NSClassFromString("SwiftyDemo.ViewController") as? UIViewController.Type let vc = rootControl?.init() window?.rootViewController = vc window?.makeKeyAndVisible() return true } 同时可以用info.plist获取命名空间 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { window = UIWindow(frame: UIScreen.main.bounds) // 依据String名字拿到控制器(添加项目名称,命名空间,不能有数字和特殊符号) // 返回的是AnyClass? 需要as?强转 // 控制器添加Type类型 // let rootControl = NSClassFromString("SwiftyDemo.ViewController") as? UIViewController.Type // 获取命名空间的值,可选 let str = Bundle.main.infoDictionary?["CFBundleName"] as? String ?? "" let con = NSClassFromString(str + "." + "ViewController") as? UIViewController.Type let vc = con?.init() window?.rootViewController = vc window?.makeKeyAndVisible() return true }
|
请发表评论