Skip to content

Instantly share code, notes, and snippets.

@cybercase
Last active July 12, 2018 15:21
Show Gist options
  • Save cybercase/7d4bb24880be5446e7a9589026f89aec to your computer and use it in GitHub Desktop.
Save cybercase/7d4bb24880be5446e7a9589026f89aec to your computer and use it in GitHub Desktop.
Debug responder chain in Cocoa
class CustomWindow: NSWindow {
override init(contentRect: NSRect, styleMask style: NSWindow.StyleMask, backing backingStoreType: NSWindow.BackingStoreType, defer flag: Bool) {
super.init(contentRect: contentRect, styleMask: style, backing: backingStoreType, defer: flag)
}
override func makeFirstResponder(_ responder: NSResponder?) -> Bool {
self.printResponderChain(responder)
return super.makeFirstResponder(responder)
}
func printResponderChain(_ responder: NSResponder?) {
guard let responder = responder else { return; }
Swift.print(responder)
printResponderChain(responder.nextResponder)
}
override func sendEvent(_ event: NSEvent) {
super.sendEvent(event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment