The UIViewController lifecycle

UIKit Junior Swift 5.0+ iOS 17+ Reviewed By Alok Singh

Order the steps

Put these callbacks in the order they run when a view controller is created and shown for the first time.

  • init(coder:) or init(nibName:bundle:)
  • viewIsAppearing
  • viewWillAppear
  • loadView
  • viewDidAppear
  • viewDidLoad
Hint 1 of 1

The view is loaded lazily, before any appearance callbacks.

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A D F C B E

  1. init(coder:) or init(nibName:bundle:) The object is created first; no view exists yet.
  2. loadView The view is created lazily when first needed.
  3. viewDidLoad Runs once after the view is loaded: one-time setup.
  4. viewWillAppear Called each time the view is about to appear.
  5. viewIsAppearing Traits and geometry are now up to date; good for appearance-time updates.
  6. viewDidAppear The view is on screen; start animations or analytics here.

30-second answer

A view controller is created (init), loads its view lazily (loadView, then viewDidLoad once), and then goes through appearance callbacks each time it is shown: viewWillAppear, viewIsAppearing, viewDidAppear, and later viewWillDisappear and viewDidDisappear. Do one-time setup in viewDidLoad, and geometry or trait-dependent updates in viewIsAppearing or layout callbacks.

Practise saying it · 45 s. No recording, just a timer

Walk through the view controller lifecycle.

Say your answer out loud, then check which of these points you covered:

  • init → loadView → viewDidLoad
  • Appearance callbacks repeat
  • viewIsAppearing for geometry/traits

Deep dive

viewIsAppearing (back-deployed to iOS 13) runs when traits and geometry are up to date, the best place for appearance-time UI updates.

viewWillLayoutSubviews / viewDidLayoutSubviews can run many times; keep them cheap.

Don't touch the view in init; it triggers loadView early.

Start and stop observers or timers in appear/disappear pairs.

Common mistakes

  • Doing size-dependent work in viewDidLoad.
  • Heavy work in viewDidLayoutSubviews.

Senior take & follow-ups

Seniors mention viewIsAppearing and explain why geometry isn't final in viewDidLoad.

Follow-up questions

Think of your answer first, then open the hint.

  1. Where do you update UI that depends on the trait collection?

    Show hint

    viewIsAppearing, or the trait change registration API.

  2. Is viewDidLoad called again when you navigate back?

    Show hint

    No, only once per view load.

Suggest a fix if something here is wrong or out of date.