Browse Questions
  • MVVM (Model-View-ViewModel) separates business logic from UI.
  • Use a computed property for a cheap, side-effect-free value derived from existing state; use a method for expensive work, side effects, or anything that needs arguments.
  • A Task is Swift's unit of async work.
  • The responder chain is a sequence of UIResponder objects that can handle events (touches, key presses, actions).

Answer: The responder chain is a sequence of UIResponder objects that can handle events (touches, key presses, actions). Events travel up the chain until something handles them.

UIView → parent UIView → UIViewController → UIWindow → UIApplication → AppDelegate

Code Example:

// Custom action sent up the responder chain
// No need to know which object handles it
UIApplication.shared.sendAction(#selector(handleLogout), to: nil, from: nil, for: nil)

// Any UIResponder in the chain can handle it
class RootViewController: UIViewController {
    @objc func handleLogout() {
        // Handles the action wherever it is in the chain
        AuthManager.shared.logout()
    }
}

// First responder — the view currently receiving input
textField.becomeFirstResponder()  // show keyboard
textField.resignFirstResponder()  // hide keyboard