How to make your .xib your root navigation — Swift

Photo from Unsplash by Aleksi Tappura

In this blog, we will be focusing on removing the .storyboard and making .xib your root navigation.

Initially, create a new Project

Your Folder structure will look like this, right?

Removing the Files

Remove Main.storyboard and ViewController.swift Files which are not needed.

Creating a .xib File

Press Command + N and select Cocoa Touch Class and in subclass of Select any Controller and check the create XIB file option. Two New Files will be created of LoginVC.swift and LoginVC.xib.

Adding static function in LoginVC

Add this static function loadFromNib code in your Controller. It Basically loads your .XIB file and return to the UIViewController and I have added a backgroundColor to differentiate the view is loaded or not.

Configuring in your main project

Select your main Project and under General tab in Main Interface Select the LoginVC.xib file.

Configuring in info.plist

In you Info.plist File under Application Scene Manifest -> Scene Configuration -> Application Session Role -> Item 0, Remove the Storyboard Name which will be under Item 0.

After removing your info.plist will somewhat look like this.

Changes in SceneDelegate.swift

Next in SceneDelegate, If you need to navigate between screens then, in that case, wrap the LoginVC in UINavigatonController else you can simply pass LoginVC.loadFromNib() to the window?.rootViewController.

After Running the project




I’m an IOS, Flutter Developer and now a Blogger

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

iOS Environment Setup

6 Easy Steps to Find Unique Device Identifier on the iPhone


Some tips in Swift

Solving iPhone bottom notch problem in Flutter

Swift Optionals. To Use or Not to Use? Cleaning Our Code.

All You Need To Know About Drag and Drop — iOS 11 — Part 1

How Does Swift Type Inference Work?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Agnel Selvan

Agnel Selvan

I’m an IOS, Flutter Developer and now a Blogger

More from Medium

Google Login in Swift 5

iOS dev— import music from user’s device using document picker

Installing Plugman and creating Cordova plugin (iOS) using Swift — Part Two

Initializers in Swift — Part 3/3 (Summary and Rules)