Last active
July 12, 2018 15:21
-
-
Save cybercase/7d4bb24880be5446e7a9589026f89aec to your computer and use it in GitHub Desktop.
Debug responder chain in Cocoa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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