0

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() { 
  ...
}
Arasuvel
  • 2,971
  • 1
  • 25
  • 40
joenotjoe
  • 11
  • 4

1 Answers1

-1

Seems method swizzling is the most common approach to this.

joenotjoe
  • 11
  • 4