Xcode 11 (Swift 5) – Creating an App without Storyboard

The previous tutorial in creating an app without a Storyboard was for iOS 12 or below. In this updated tutorial (October 2019), the target is for iOS 13.

Creating a Project

Open XCode (Version 11A420a; as of October 2019) and click Create a new Xcode project.

Xcode version 11A420A (October 2019)

Select Single View App and press the Next button.

Select Single View App and press Next

Enter the name of the product (app name), select Swift as your language, and UI is Storyboard, uncheck Use Core Data, and press the Next button. Core Data means to have a local database in the app (I will cover this in future tutorials).

Enter the name of the product, language set to Swift, User Interface set to Storyboard, uncheck Use Core Data, and click Next.

Save the project by pressing the Create button.

Save your desire location.

Deleting Main.Storyboard

First, change the iOS Target requirements (optional). Second, erase the Main and Main Interface blank, and delete Main.storyboard.

Target: iOS 13

Delete Main and leave Main Interface field blank.

Remove “Main” from Main Interface and leave it blank.

Open Info.plist file. In the Info.plist:

  • Open Application Scene Manaifest
  • open Scene Configuration
  • open Application Session Role
  • open Item 0 (Default Configuration)
  • Press the minus sign on the Storyboard Name.
Delete Storyboard Name

The Storyboard Name is removed.

Storyboard Name was removed

Delete Main.storyboard file.

Delete Main.Storyboard

Press Move to Trash button.

Move to trash

Also, delete ViewController.swift.

Delete ViewController

Press Move to Trash button.

Move to trash

Scene Folder

Add a group and call it Scenes. The Scenes folder will contain views. Each views will have a View and a Controller. The View will manage the user interface and the Controller will manage the backend or events of the view.

Create a new folder

After creating a folder called Scenes, create another folder inside Scenes called Home.

Create a folder called Scenes. Inside Scenes, create another folder called Home.

Adding our file scenes (View and Controller)

Add a Swift file inside the Home folder.

Select Swift File and press the Next button.

Select Swift file and press Next

Under the Home folder, name a Swift file called HomeView. After changing the name, press the Create button.

Save it under the Home folder

Create another Swift file called HomeController.

Two new Swift files created under Home.

HomeView Source Code

Open the HomeView.swift file and enter the following source code:

import UIKit

class HomeView: UIView {
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    override init(frame: CGRect) {
        super.init(frame: frame)
        Setup()
    }
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented.")
    }
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    func Setup(){
        self.backgroundColor = .systemGray
    }
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
}
HomeView source code

HomeController Souce Code

Open the HomeController.swift file and enter the following source code:

import UIKit

class HomeController: UIViewController {
    var homeView: HomeView!
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    override func viewDidLoad() {
        super.viewDidLoad()
        setupView()
    }
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
    }
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    func setupView() {
        let mainView = HomeView(frame: self.view.frame)
        self.homeView = mainView
        self.view.addSubview(homeView)
        homeView.topAnchor.constraint(equalTo: view.topAnchor, constant: 0).isActive = true
        homeView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0).isActive = true
        homeView.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: 0).isActive = true
        homeView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0).isActive = true
        homeView.translatesAutoresizingMaskIntoConstraints = false
    }
    // + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
}
HomeController source code.

Adding a snippet in SceneDelegate.swift

Open the SceneDelegate.swift.

Click SceneDelegate.swift

In SceneDelegate.swift, add the following source code inside the scene method. This snippet will point to the main controller (in this example, HomeController is our main starting point after the Launch Screen).

guard let windowScene = (scene as? UIWindowScene) else { return }
        
window = UIWindow(frame: windowScene.coordinateSpace.bounds)
window?.windowScene = windowScene
window?.rootViewController = HomeController()
window?.makeKeyAndVisible()
A snippet was inserted in the scene method.

Run the App

Run the application by pressing the PLAY (or Command and R on your keyboard).

Press the run (or play button)

And here is the app running without a Storyboard. The next tutorial, I will go over on how to add contents.

App is running without the Storyboard