Setup UIKIT Without StoryBoard

Luiz Gabriel - Sep 1 - - Dev Community
  • First you need create a new project

create new project

  • Delete the file main from your project

file main

  • after that we will have to clean some properties where it refers to file main
  • click on the symbol ➖ and delete the property Storyboard Name

property Storyboard Name

  • Access the main file, go to "build settings" and search about the reference "main"
  • delete the value's property

build settings

  • access the file scene delegate
  • inside function "scene", we will add this code above
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
  guard let windowScene = (scene as? UIWindowScene) else { return }
  let window = UIWindow(windowScene: windowScene)
  let vc = ViewController()
  window.rootViewController = vc
  window.makeKeyAndVisible()
  self.window = window
}
Enter fullscreen mode Exit fullscreen mode

To test if works it, access the viewController add this line inside the method viewDidLoad()

import UIKit

class ViewController: UIViewController {
  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .yellow
  }
}
Enter fullscreen mode Exit fullscreen mode

Just execute and magic happens 🍏

. . . . . . . . .