Skip to content

Instantly share code, notes, and snippets.

@chunkyguy
Created November 26, 2019 21:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chunkyguy/3655a09757659151cb4f06e0e85f5f3b to your computer and use it in GitHub Desktop.
Save chunkyguy/3655a09757659151cb4f06e0e85f5f3b to your computer and use it in GitHub Desktop.
A minimal iOS 13 app with no storyboard or xib
import UIKit
// MARK: - ViewController
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .red
}
}
// MARK: - App
class App {
static let app = App()
private var window: UIWindow?
func start(window: UIWindow = UIWindow(frame: UIScreen.main.bounds)) {
window.rootViewController = ViewController()
window.makeKeyAndVisible()
self.window = window
}
}
// MARK: - AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder {}
// MARK: UIApplicationDelegate
extension AppDelegate: UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
if #available(iOS 13.0, *) {} else {
App.app.start()
}
return true
}
}
// MARK: UIWindowSceneDelegate
@available(iOS 13.0, *)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = scene as? UIWindowScene else {
return
}
let window = UIWindow(windowScene: windowScene)
App.app.start(window: window)
}
}
@available(iOS 13.0, *)
extension AppDelegate {
func application(
_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(
_ application: UIApplication,
didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment