Creating Xcode Project Without Storyboards - cobocombo/Scriptit-Core GitHub Wiki

Create Default Xcode Project

  • Start Xcode application and select Create New Project.
  • Select "iOS", "App" and then "Next".
  • Enter project settings. Verify interface is storyboard and language is swift. Hit "Next".
  • Select a directory to save the project and hit "Create".

Remove Main.storyboard

  • Delete the Main.storyboard file and make sure you select the "Move to trash" option to completely remove it.

Remove Reference To Main.storyboard From Deployment Info

  • Go to the "Build Settings" tab and search for the "UIKit Main Storyboard File Base Name" key. Then remove the key or set the value to empty.

Remove Info.plist Storyboard Name Key

  • Open your Info.plist.
  • Click the arrow at the leftmost of Application Scene Manifest (UIApplicationSceneManifest) key to expand.
  • Click the arrow at the leftmost of Scene Configuration (UISceneConfigurations) key to expand.
  • Click the arrow at the leftmost of Application Session Role (UIWindowSceneSessionRoleApplication) key to expand.
  • Click the arrow at the leftmost of First Item (Item 0) key to expand.
  • Remove the key Storyboard Name (UISceneStoryboardFile).

Create The Main Window

  • We need to initialize window and set the rootViewController manually. We do this in in the SceneDelegate.swift.
  • Change the following function from this:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let _ = (scene as? UIWindowScene) else { return }
}
  • To this:
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    guard let windowScene = (scene as? UIWindowScene) else { return }
  
    let window = UIWindow(windowScene: windowScene)
    window.rootViewController = ViewController()   
    window.makeKeyAndVisible()
    self.window = window
}
  • In ViewController.swift, modify the viewDidLoad method to change the background color to red. This is to verify our changes actually work:
override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = .red;
  }

Launch App In Simulator

  • Launching the app in the simulator should show your view controller with a red background: