The programatic ios app


My checklist when making a programtic iOS app

  1. Clean up the AppDelegate class:
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
   var window: UIWindow?
   func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {return true}
}
  1. Delete Main storyboard file base name in the info.plist
  2. Now you can delete ViewController.swift
  3. Add MainVC and MainView
class MainVC :UIViewController{
	override func viewDidLoad() {
      super.viewDidLoad()
      view = MainView()
      view.backgroundColor = .orange
   }
}
class MainView:UIView{}
  1. Add a Window and a ViewController to the app:
lazy var window: UIWindow? = {
   let win = UIWindow(frame: UIScreen.main.bounds)
   let vc = MainVC()
   win.rootViewController = vc
   win.makeKeyAndVisible()/*Important since we have no Main storyboard anymore*/
   return win
}()
  1. CMD + R Run the app, if the background is orange it works