How to make your .xib your root navigation — Swift
--
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