Browse Questions
  • Use a custom URLProtocol subclass that intercepts URLSession requests and returns fake responses — no network needed, tests run instantly.
  • OperationQueue is a higher-level abstraction over GCD.
  • A UIViewController goes through a predictable sequence of method calls as its view is created, displayed, and removed.
  • @AppStorage is a property wrapper that reads and writes to UserDefaults and automatically refreshes the view when the value changes.

Answer: A UIViewController goes through a predictable sequence of method calls as its view is created, displayed, and removed.

init → loadView → viewDidLoad → viewWillAppear → viewDidAppear
                                                        ↓
                               viewWillDisappear → viewDidDisappear → deinit

Key methods and their purpose:

class MyViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Called once — set up UI, configure views, add subviews
        setupUI()
        bindViewModel()
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        // Called every time view is about to appear — refresh data, show nav bar
        navigationController?.setNavigationBarHidden(false, animated: animated)
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        // View is visible — start animations, begin location updates
    }

    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // About to leave — pause video, resign first responder
    }

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
        // Gone — stop timers, save state
    }
}