45
Setup iOS Project without Storyboard
Storyboard first introduced on iOS 5 is a feature for building UI (User Interface) on iOS app. Storyboard allows us to quickly build a UI because the process is done visually with little or no coding.
Easy to use, Storyboard is designed for creating UIs quickly and easily. Storyboard uses a drag-and-drop mechanism to build the UI.
Great for prototyping, You may have no time to build UI with code. Here, Storyboard comes to the rescue to help you build your UI many times faster than coding.
Makes code review harder, Storyboard generates XML code when you make UI changes in your Storyboard files. XML code generated by Storyboard is harder to read and it makes the code review process much harder than without Storyboard files.
Hard to refactor, At the time you might have to refactor your
UITableViewController
intoUICollectionViewController
or from one view controller type into a different view controller type, it’s hard to solve if you use Storyboard because you need to delete the entire view controller you want to change and this is risky.
The first thing you need to do is create a new iOS project with UIKit using Xcode and remove the Main.storyboard
file, if the Xcode shows the option to remove let’s select Move to Trash.
Next, open the SceneDelegate.swift
file and change the body of the scene
method onto code like below
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
let viewController = ViewController()
let navigationController = UINavigationController(rootViewController: viewController)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}
Next, open the Info.plist
file and remove Storyboard Name
and Main storyboard file base name
properties.
The last step, build and run the project. If the project running without errors then congrats! Now your project can run without Storyboard!
45