Starting an iOS project without storyboard

Dowanna
2 min readJul 12, 2018

--

Storyboards can be difficult to handle in a team, since multiple members working on the same file may create conflict. It comes handy to know how to create an iOS project without storyboard, but using the capability of IB to create views from a XIB file.

In this article (and some related articles) I will show:

  1. How to create an initial ViewController upon launch without storyboard
  2. How to instantiate a view from a xib file
  3. How to attach a full-size view to the initial ViewController

How to create an initial ViewController upon launch without storyboard

  • Create a Simple View Application by Xcode, and remove the storyboard from your project.
  • Modify the project's Info.plist. "Main storyboard file base name" defaults to "Main", so modify this to a blank value. If this value remains "Main", our project will search for a Main.storyboard (which we have deleted) upon launch
  • Modify AppDelegate.swift as below.
  • UIWindow(frame: UIScreen.main.bounds) creates a UIWindow object with equivalent size as the iOS device’s screen (UIScreen)
  • UIWindow object requires a rootViewController. As the document states below, nothing will be displayed if the rootViewController is unassigned.

The root view controller provides the content view of the window. Assigning a view controller to this property (either programmatically or using Interface Builder) installs the view controller’s view as the content view of the window.

  • makeKeyAndVisible() tells the window to show in the front-end. Note that it is also possible to show the window by

self.window?.isHidden = true.

However every app needs a key window, and the document states:

Whereas touch events are delivered to the window where they occurred, events that do not have a relevant coordinate value are delivered to the key window.

So I always tend to use makeKeyAndVisible() to the main window.

That's it! Now we can start an app without using Storyboard, and attach a ViewController to the window root.

But the current ViewController lacks a view, so nothing is shown.

Related Articles

I will explain steps 2 and 3 in a separate article, just so one article doesn't get too long, and my title actually describes what's written.

  1. How to create an initial ViewController upon launch without storyboard (which I just explained :D )
  2. How to instantiate a view from a xib file
  3. How to attach a full-size view to the initial ViewController

--

--

Dowanna

CEO of Praha Inc., an IT startup in Japan. Also an iOS / web-front engineer. https://praha-inc.com