Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 13: Swift - 'Set application root view controller programmatically' does not work

I have following code in my AppDelegate.swift to setup root view controller for an iOS application. But it does not work. It follows Target structure (defined under General tab) and ignores this code.

(Xcode 11, Swift 5.1, iOS 13)

class AppDelegate: UIResponder, UIApplicationDelegate {      var window: UIWindow?      func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {          window = UIWindow(frame: UIScreen.main.bounds)         guard let rootVC = UIViewController() else {             print("Root VC not found")             return true         }         let rootNC = UINavigationController(rootViewController: rootVC)         window?.rootViewController = rootNC         window?.makeKeyAndVisible()          return true     } } 

Unable to understand where is the issue.

I tried following references also but no luck:

  • Swift ios set a new root view controller
  • Root View Controller Swift
  • iOS: Root Controller Navigation
like image 752
Krunal Avatar asked Sep 24 '19 15:09

Krunal


People also ask

How do I create a root controller in Swift?

Go to the Project Navigator → info. plist file → Application Scene Manifest property → Scene Configuration → item 0 and get rid of the property Storyboard Name by clicking the icon that has a minus in the circle next to it.

What is Rootview controller Swift?

The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller's view as the content view of the window.


1 Answers

To choose a previous approach to the one supported by SwiftUI, from a project created in Xcode 11, you can follow these steps.

Steps for get old aproach

like image 167
Carlos García Avatar answered Oct 14 '22 11:10

Carlos García