What is the UIViewController lifecycle?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Swift & iOS topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

The UIViewController lifecycle defines the sequence of method calls as a view controller is created, becomes visible, updates, and is dismissed: (1) init(coder:) / init(nibName:bundle:): the view controller is instantiated from a storyboard or programmatically; (2) loadView(): creates the view hierarchy. Override to create the view programmatically (don't call super if you do). Otherwise, loads from nib/storyboard; (3) viewDidLoad(): called once after the view is loaded into memory. Best place for one-time setup: create subviews, configure outlets, set up data structures, subscribe to notifications; (4) viewWillAppear(_ animated: Bool): called every time before the view becomes visible. Refresh UI, re-register observers; (5) viewDidAppear(_ animated: Bool): view is fully visible. Start animations, begin expensive data fetching; (6) viewWillDisappear(_ animated: Bool): about to leave the screen. Save unsaved changes, pause ongoing tasks; (7) viewDidDisappear(_ animated: Bool): view is no longer visible. Stop timers, unregister observers; (8) viewWillLayoutSubviews() / viewDidLayoutSubviews(): called when bounds change. Update frames calculated from bounds; (9) deinit: view controller is deallocated — final cleanup. Memory warning: didReceiveMemoryWarning() — release cached data. Important: always call super in lifecycle methods. viewDidLoad is called once; viewWillAppear/viewDidAppear may be called multiple times.

Pro Tip

Demonstrate both theoretical understanding and practical experience. Say what it is, then give an example of how you actually used it in a Swift & iOS codebase.