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.

  1. In what order do updateConstraints, the controller hooks and layoutSubviews run, and where should each kind of work go? 7.11.1 · L3
    Auto Layout runs as separate passes, each triggered by its own flag. setNeedsUpdateConstraints() schedules the constraint pass, where updateViewConstraints()…
  2. Which UIKit patterns keep a view controller alive after it is dismissed, and how do you break each one? 7.11.2 · L3
    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.

  1. How are UIMenu, UIAction and deferred elements structured, and where are menus used? 7.11.3 · L2
    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