Xcode

How To Start An Xcode Project Without Storyboards

In this guide, you’ll learn how to start a new Xcode project without storyboards. I prefer to take a full programmatic approach to laying out my UI so when I start a new project, I always follow these steps to make sure the storyboard has been properly removed.

Delete The Storyboard

The first and most obvious step is to actually delete the Main.storyboard file. To do so, right-click on the file in the project navigator and select Delete. Once the confirmation popup appears, select Move to Trash.

Edit Main Interface

Next, go to the project settings and delete any text in the Main Interface box.

Main Interface

Edit Info.plist

We next need to delete one final trace of the storyboard in info.plist. You can search the project for main or manually find the row in the file. Once you’ve found it, just delete the row named Storyboard Name.

Info.plist

SceneDelegate.swift

The last thing to do is to add the follow lines of code into the SceneDelegate.swift file. This code will replace the method at the top of the file.

var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return } // 1
    window = UIWindow(frame: windowScene.coordinateSpace.bounds) // 2
    window?.windowScene = windowScene // 3
    window?.rootViewController = ViewController() // 4
    window?.makeKeyAndVisible() // 5
}
  1. This window scene is used to create the window
  2. Here, we are initialising the window to be the size of the device screen
  3. Setting the window’s windowScene to the one we created
  4. This is where the view controller is added to the window. Feel free to add any of your view controllers or even a tab bar controller
  5. The final line just makes the window visible so it can be seen within the app

Test If It All Works

To make sure the above code works, we can go into the ViewController.swift file and change the background colour.

view.backgroundColor = .orange

Now you can run your app and you should see an orange view controller presented.

Thanks for reading!