My checklist when making a programmatic iOS app
- Clean up the
AppDelegate.swift
class and add a Window variable: - Delete
Main storyboard file base name
in the info.plist (since xcode 11 also remove scenedelegate) - Now you can delete ViewController.swift
and
Main.storyboard (since xcode 11 also remove scenedelegate) - Add MainVC and MainView
CMD + R
Run the app, if the background is orange it works
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
lazy var window: UIWindow? = createWindow()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
_ = window
return true
}
}
extension AppDelegate {
func createWindow() -> UIWindow {
let win = UIWindow(frame: UIScreen.main.bounds)
let vc = ViewController()
win.rootViewController = vc
win.makeKeyAndVisible() // Important since we have no Main storyboard anymore
return win
}
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view = View()
view.backgroundColor = .orange
}
override var prefersStatusBarHidden: Bool { return false }
}
class View: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
}
/**
* Boilerplate
*/
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}