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.
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.
Next, go to the project settings and delete any text in the Main Interface box.
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.
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
}
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!