Func Application (_ Application:uiapplication, didfinishlaunchingwithoptions launchoptions: [ Uiapplicationlaunchoptionskey:any]?) -Bool {window=UIWindow (frame:UIScreen.main.bounds)//get controller based on string name (add project name, namespace, cannot have numbers and special symbols)//is the Anyclass returned? Need as? Strong Turn//controller Add typeLet Rootcontrol = nsclassfromstring ("Swiftydemo.viewcontroller") as?Uiviewcontroller.type Let VC= Rootcontrol?. init () window?. Rootviewcontroller =VC Window?. makekeyandvisible ()return true }
You can also get namespaces with Info.plist
Func Application (_ Application:uiapplication, didfinishlaunchingwithoptions launchoptions: [ Uiapplicationlaunchoptionskey:any]?) -Bool {window=UIWindow (frame:UIScreen.main.bounds)//get controller based on string name (add project name, namespace, cannot have numbers and special symbols)//is the Anyclass returned? Need as? Strong Turn//controller Add type//Let Rootcontrol = nsclassfromstring ("Swiftydemo.viewcontroller") as? Uiviewcontroller.type//gets the value of the namespace, optionallyLet 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 }
Swift reflection mechanism implements the Appdelegate string fetch class and becomes the root controller