How to create a new Xcode project without Storyboard

Xcode Workflow

When you create a new project in Xcode, the default boilerplate includes the Main.storyboard. If you are going with a no storyboard approach and want to set everything up in code, there are a few steps you need to do.

Pre Xcode 11

Everyone should be on Xcode 11 by now, but I will add this here for completeness.

Remove Main.storyboard

Delete Main.storyboard file and make sure you select "Move to trash" option to remove it completely.

Remove reference to Main.storyboard

  1. Click on your project root level on the left panel
  2. Select your app target
  3. Click General tab
  4. Under Deployment Info section you will find Main Interface field
  5. Delete "Main" and leave it blank

Create the main window

If the application has a Storyboard set as the Main Interface, the window property will automatically be initialized, and its root view controller is set to the storyboard's initial view controller. Since we already removed it, we need to initialize window and set rootViewController manually. In pre Xcode 11, we do this in appDelegate.

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = ViewController() // Your initial view controller.
window.makeKeyAndVisible()
self.window = window
return true
}

That's all.

Xcode 11

To support multiple windows in iOS 13, Xcode 11 boilerplate is a little bit different than in Xcode 10. The most noticeable change is the introduction of the new SceneDelegate.

Remove Main.storyboard

The first step is the same, delete Main.storyboard file and make sure you select "Move to trash" option to completely remove it.

Remove reference to Main.storyboard from Deployment Info

  1. Click on your project root level on the left panel
  2. Select your app target
  3. Click General tab
  4. Under Deployment Info section you will find Main Interface field
  5. Delete "Main" and leave it blank

Remove new Info.plist key-value, UISceneStoryboardFile

Removing "Main" from Main Interface is not enough (I think this might be a bug), you have to delete another reference to Main.storyboard hidden inside Info.plist

Open your Info.plist

  1. Click the arrow at the leftmost of Application Scene Manifest (UIApplicationSceneManifest) key to expand
  2. Click the arrow at the leftmost of Scene Configuration (UISceneConfigurations) key to expand
  3. Click the arrow at the leftmost of Application Session Role (UIWindowSceneSessionRoleApplication) key to expand
  4. Click the arrow at the leftmost of First Item (Item 0) key to expand
  5. Remove the key Storyboard Name (UISceneStoryboardFile)

If you want to do it in your text editor, search for UISceneStoryboardFile and remove both key and value.

<key>UISceneStoryboardFile</key>
<string>Main</string>

Create the main window

Just like in Xcode 10, we need to initialize window and set rootViewController manually. This time we do it in SceneDelegate.

From this:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let _ = (scene as? UIWindowScene) else { return }
}

To this:

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }

let window = UIWindow(windowScene: windowScene)
window.rootViewController = ViewController() // Your initial view controller.
window.makeKeyAndVisible()
self.window = window
}

If you enjoy this article, you can subscribe to the weekly newsletter.

Every Friday, you’ll get a quick recap of all articles and tips posted on this site — entirely for free.


← Home