7.11 · Layout passes, retain cycles and menus
The pass order that runs your layout code, the closure and target cycles that keep controllers alive, and the value-based menu API.
Mental model. Know who holds whom: a run loop, notification centre or the view itself can keep a controller alive; and know the fixed order of the update-constraints, layout and display passes.
Passes and ownership
What runs when, and what keeps a controller alive.
- In what order do updateConstraints, the controller hooks and layoutSubviews run, and where should each kind of work go?
Auto Layout runs as separate passes, each triggered by its own flag. setNeedsUpdateConstraints() schedules the constraint pass, where updateViewConstraints()… - Which UIKit patterns keep a view controller alive after it is dismissed, and how do you break each one?
A controller is freed when nothing strong points at it, so every cycle has an owner you did not notice. The check released a controller and watched deinit: it…
Menus
UIMenu, UIAction and deferred elements.
- How are UIMenu, UIAction and deferred elements structured, and where are menus used?
A menu is a tree of UIMenuElement values: UIAction leaves (title, image, state, attributes such as .destructive and .disabled, and a handler), UIMenu nodes…
More in UIKit
- 7.1 · Hit testing, the responder chain and gesture recognisers
- 7.2 · UIView and CALayer, frame, bounds and center
- 7.3 · View controller lifecycle, containment, presentation and transitions
- 7.4 · Navigation, tab, split and page controllers
- 7.5 · Compositional layout, diffable data sources, cell reuse and prefetching
- 7.6 · UITableView, still asked and still everywhere
- 7.7 · Trait collections, size classes, safe area, keyboard and appearance
- 7.8 · Keyboard shortcuts, pointer, Apple Pencil and multitasking
- 7.9 · Hosting SwiftUI in UIKit and UIKit in SwiftUI
- 7.10 · Initialisers, stack views, scroll views and modern buttons
- 7.12 · Refreshing diffable cells, outlines and carousel layouts
- 7.13 · View-tree exercises and long navigation stacks