Skip to content

Instantly share code, notes, and snippets.

@scott-lydon
Created September 23, 2022 01:59
Show Gist options
  • Save scott-lydon/b24c89c3060db711a0c0958833a80e7a to your computer and use it in GitHub Desktop.
Save scott-lydon/b24c89c3060db711a0c0958833a80e7a to your computer and use it in GitHub Desktop.
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
let viewController = ViewController.instantiate()
viewController.view.backgroundColor = .green
let navController = UINavigationController(rootViewController: viewController)
window = UIWindow(windowScene: windowScene)
window?.rootViewController = navController
window?.makeKeyAndVisible()
}
}
class ViewController: UIViewController {
@IBAction func buyTapped(_ sender: Any) {
navigationController?.pushViewController(BuyViewController.instantiate(), animated: true)
}
@IBAction func createAccount(_ sender: Any) {
navigationController?.pushViewController(CreateAccountViewController.instantiate(), animated: true)
}
}
class BuyViewController: UIViewController {}
class CreateAccountViewController: UIViewController {}
extension UIStoryboard {
static var main: UIStoryboard {
.init(name: "Main", bundle: Bundle.main)
}
}
extension UIViewController {
/// Requires the storyboard id to match the class name.
static func instantiate(storyboard: UIStoryboard = .main) -> Self {
storyboard.instantiateViewController(withIdentifier: NSStringFromClass(self).components(separatedBy: ".")[1]) as! Self
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment