Search code examples
iosswiftxcodexcode-storyboard

Storyboard not deleting in Xcode 11


I usually build UI programatically but for some reason after updating to Xcode 11, not able to remove storyboard or remove the reference. It keeps throwing an error saying storyboard missing. Usually I delete the main and go to project settings and remove the Main keyword text as well. I then delete the viewController, add a new viewController like HomeViewController and use the following code in app delegate.

var window: UIWindow?

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

        window = UIWindow()
        window?.makeKeyAndVisible()
        let nc = UINavigationController(rootViewController: HomeViewController())
        window?.rootViewController = nc

        return true
    }

I follow the exact same steps that I used to follow in previous Xcode versions and it used to work (without deleting the storyboard file itself). As long as I added the above code. Now doesn't seem to be the case. If I delete the default ViewController file and say add a new HomeViewController File and add the above code, throws an error saying storyboard is missing or storyboard does not contain HomeViewController.


Solution

  • You don't say, but I'm assuming you're creating a new project with an iOS 13 target? If not, you can ignore this :-)

    In XCode 11 for a new iOS 13+ project they changed the way initiating a UI from code works. It no longer takes place within the AppDelegate but in the SceneDelegate.

    After I'd spent far too long working out what was going on I wrote it up in a blog post with the idea it may help someone else. Rather than rehashing it all, I'll link to it:

    XCode 11 New Project Without Storyboard