Xcode
iOS Development
Swift
Empty Application
No Storyboard

How to create an Empty Application in Xcode without Storyboard

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Creating an empty application in Xcode without using a storyboard provides flexibility and a deeper understanding of how iOS applications work under the hood. This approach is especially beneficial for developers who want to manage the views programmatically. Here’s a step-by-step guide on how to do it.

Overview

Xcode traditionally uses storyboards to visually design the user interface of an iOS application. By not using a storyboard, developers can create UI components directly in code, offering better control and potentially reducing runtime issues related to storyboard rendering.

Requirements

  • Xcode: Ensure you have Xcode installed. This guide assumes you have already set up Xcode and are familiar with its basic operation.

Step-by-Step Guide

1. Create a New Xcode Project

  • Open Xcode and click on "Create a new Xcode project."
  • Select "App" under the iOS tab and click "Next."
  • Enter the project name and other relevant details.
  • Disable the "Use Storyboards" option by deselecting the "Use Interface Builder" checkbox. Make sure only "Swift" for language is selected.

2. Remove Main Storyboard

Xcode creates a Main.storyboard file by default. Since we are not using it, let’s remove it.

  • Navigate to the project navigator and delete Main.storyboard.
  • After deleting, make sure to remove any references to it in the project settings:
    • Select your project in the project navigator.
    • Go to the "Info" tab.
    • Find and delete the entry for "Storyboard Name" by removing Main from the main interface.

3. Set Up the Entry Point Programmatically

Modify the AppDelegate to set up the window and the initial view controller.

  • Open the AppDelegate.swift file.
  • Modify the application(_:didFinishLaunchingWithOptions:) method as follows:
  • Open ViewController.swift.
  • Inside ViewController.swift, set up the view using code:
  • Open SceneDelegate.swift.
  • Modify scene(_:willConnectTo:options:) method:
  • Auto Layout: When crafting your UI programmatically, Auto Layout can still be used to ensure that your views are correctly sized and positioned across different devices.
  • Reusability: Define custom UI components in separate classes or extensions to enhance modularity and reusability.
  • Lifecycle Management: Without a storyboard, managing the lifecycle becomes more explicit. Ensure that views are loaded/unloaded correctly to manage memory efficiently.
  • Code Organization: Use extensions and separate files to compartmentalize and organize code logically, especially when expanding UI features.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.