Created
November 26, 2019 21:20
-
-
Save chunkyguy/3655a09757659151cb4f06e0e85f5f3b to your computer and use it in GitHub Desktop.
A minimal iOS 13 app with no storyboard or xib
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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