'Event Delegation like in JavaScript, but in iOS Swift

Is there a way in Swift to capture events on a screen similar to how Event Delegation in JavaScript works? I would like to find a way to respond to events without having to embed logging calls to each method. I believe UIResponder might have this ability, but I it's not clear how to listen for all UIEvents.

For example:

extension UIResponder {
  func listenForAllButtonTaps() {
    // listen to all button taps, figure out the button and screen, log to logger
    
  }
}

@objc func buttonOne() { 
  // no logging method 
  ...
}

@objc func buttonTwo() { 
  ...
}


Solution 1:[1]

Seems method swizzling is the most common approach to this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 joenotjoe