0

This code is in the AppDelegate. Xcode doesn't throw any errors, but this code doesn't work when I recall the func in other View Controller buttons. ( Either make the app open on View Controller VC1 or VC2 ) The recall code: (UIApplication.shared.delegate as! AppDelegate).configureInitialViewController()

class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        configureInitialViewController()
        return true
    }

    **// determins which VC will be initially launched.**
    func configureInitialViewController() {
        var initialVC: UIViewController
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        if 1 > 0 {
            initialVC = storyboard.instantiateViewController(withIdentifier: VC1)
        } else {
            initialVC = storyboard.instantiateViewController(identifier: VC2)
        }
        window?.rootViewController = initialVC
        window?.makeKeyAndVisible()

    }
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
Vidal Singh
  • 123
  • 1
  • 6

1 Answers1

0

Used your advice matt. ( SceneDelegate.swift file ) This is the code:

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: windowScene.coordinateSpace.bounds)
        window?.windowScene = windowScene
        if 1 > 0 {
            window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "INPUT YOUR STORYBOARD ID HERE")
        } else {
            window?.rootViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "INPUT YOUR STORYBOARD ID HERE")
        }
        window?.makeKeyAndVisible()


}
Vidal Singh
  • 123
  • 1
  • 6