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

SWIFTip#5: Casual insight of the week

iOS: Creating and designing a data model with Core Data

How to build an iPhone app in 4 weeks

How to: Generate App Clip Codes

Images loader and memory footprint. iOS

How to: Add Firebase to SwiftUI 2 (2020)

How to run a App on iOS simulator without open Xcode

How to make protocol work in SwiftUI

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

How to create an Xcode project and connect it to Github?

WebEngage in iOS

iOS Application Localization

Google Login in Swift 5