joethemow
joethemow

Reputation: 1773

I am not using storyboard AT ALL but I am still getting this error

I am not using main.storyboard at all and making everything through code, but I get this error with this code in my app delegate.

Failed to instantiate the default view controller for UIMainStoryboardFile 'Main' - perhaps the designated entry point is not set?

var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        let rootView = HomeCollectionViewController(collectionViewLayout: UICollectionViewFlowLayout())

        if let window = self.window {
            window.rootViewController = rootView
        }

        return true
    }

Upvotes: 1

Views: 261

Answers (3)

ridvankucuk
ridvankucuk

Reputation: 2407

Above my comment, adding an answer. If you are using a storyboard which is dummy for you at this point, you should add a View Controller to your UIStoryboard. If you want to remove your UIStoryboard, you can still continue without it. In stackoverflow its been answered here.

Upvotes: 0

Salman Ghumsani
Salman Ghumsani

Reputation: 3657

You can just delete the key from your .plist file Main storyboard file baseand run it again.

Also if you are getting the black screen you have to setup window by self.window?.makeKeyAndVisible() like above answer.

Upvotes: 1

GoodSp33d
GoodSp33d

Reputation: 6282

If you are not planning on using the storyboard you need to still make some configurations in the project file to let the Xcode know. Under target -> Deployment info you can see a setting for Main Interface, set it as blank then it will not look for the entry point in the storyboards.

enter image description here

Also, when you are doing everything in code, UIWindow instance needs to be instantiated and made visible which allows you to start presenting view controllers.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let viewController = TestViewController()

    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = viewController
    self.window?.makeKeyAndVisible()

    return true
}

Upvotes: 2

Related Questions