Skip to content

Instantly share code, notes, and snippets.

@Geri-Borbas
Last active May 17, 2022 02:00
Show Gist options
  • Save Geri-Borbas/9f4fa0a9ab6552151bdf408729a4cd11 to your computer and use it in GitHub Desktop.
Save Geri-Borbas/9f4fa0a9ab6552151bdf408729a4cd11 to your computer and use it in GitHub Desktop.
Create UI in code template from storyboard templates.
  1. Remove Main.storyboard file from the bundle.
  2. Remove main from Target/General/Main Interface
  3. Remove Main from Info.plist at Application Scene Manifest/Scene Configuration/Application Session Role/Default Configuration.
  4. Instantiate window with first view controller in SceneDelegate.

Replace this method.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
    // If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
    // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
    guard let _ = (scene as? UIWindowScene) else { return }
}

With this.

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
    if let windowScene = scene as? UIWindowScene {
        let window = UIWindow(windowScene: windowScene)
        window.rootViewController = ViewController()
        self.window = window
        window.makeKeyAndVisible()
    }
}

Which resembles the iOS 13 SwiftUI template by the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment