Skip to content

UIKit's event-driven mental model and app lifecycle

UIKit builds interfaces from long-lived objects. Views and controllers receive events, mutate properties, coordinate children, and respond to lifecycle callbacks.

Follow the ownership chain

UIApplication
|
v
UISceneSession -> UIWindowScene -> UIWindow
|
v
root view controller
|
v
view hierarchy

The application coordinates process-level events. Each scene represents one interface instance. A window presents a root controller. Controllers coordinate a screen or contained region, not the entire product and not the durable domain model.

Launch a programmatic scene

import UIKit
final 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 window = UIWindow(windowScene: windowScene)
window.rootViewController = UINavigationController(
rootViewController: NoteListViewController()
)
self.window = window
window.makeKeyAndVisible()
}
}

The composition root should inject the note library rather than let the controller construct persistence or networking dependencies.

Treat callbacks by repeat behavior

viewDidLoad runs after the controller loads its view and fits one-time hierarchy setup. Appearance callbacks can run many times. Layout callbacks can run frequently. Starting an unguarded fetch in viewDidLayoutSubviews can create a request loop.

@MainActor
final class NoteListViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
title = "Field Notes"
view.backgroundColor = .systemBackground
configureHierarchy()
configureConstraints()
}
}

UIKit events arrive through target-action, delegates, notifications, data sources, gestures, and the responder chain. The main run loop processes events and schedules interface work. UI mutation stays on the main actor.

Scenes can outlive assumptions

The app may have several scenes. A scene can move through foreground and background without the process terminating. Persist valuable work before relying on a later callback, and make lifecycle handling safe to repeat.

Validation boundary

The code was not compiled or launched. Scene configuration, Info.plist wiring, lifecycle order, run-loop behavior, and main-thread diagnostics remain Not verified.

Series navigation

References