Skip to content

Instantly share code, notes, and snippets.

@anoop4real
Last active March 18, 2023 05:18
Show Gist options
  • Save anoop4real/2f99a4b8e07a772d64cb5b56f9c256bb to your computer and use it in GitHub Desktop.
Save anoop4real/2f99a4b8e07a772d64cb5b56f9c256bb to your computer and use it in GitHub Desktop.
No Storyboard scene delegate snippet

Snippet for my video No Storyboards

SWIFT

    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 windowScene = (scene as? UIWindowScene) else { return }
        window = UIWindow(frame: UIScreen.main.bounds)
        let vc = ViewController()
        let navVC = UINavigationController(rootViewController: vc)
        window?.rootViewController = navVC
        window?.makeKeyAndVisible()
        window?.windowScene = windowScene
    }

OBJECTIVE- C

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)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).
  UIWindowScene * windowScene = (UIWindowScene*) scene;
  _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  ViewController* initialViewController = [[ViewController alloc] init];
  UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:initialViewController];
  _window.rootViewController = navController;
  [_window makeKeyAndVisible];
  _window.windowScene = windowScene;
}

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