Skip to content

Instantly share code, notes, and snippets.

@stephancasas
Created March 18, 2024 20:35
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephancasas/7580e4970503970390c903ec16edc109 to your computer and use it in GitHub Desktop.
Save stephancasas/7580e4970503970390c903ec16edc109 to your computer and use it in GitHub Desktop.
An extension on NSApplication providing a computed property that describes the current responder chain.
//
// NSApplication+NSResponderDebug.swift
//
// Created by Stephan Casas on 3/18/24.
//
import Cocoa;
extension NSApplication {
/// Returns a description of the `NSResponder` responder chain starting from the first responder.
var responderChainDebugDescription: String {
(self as AnyObject).perform(
NSSelectorFromString("_eventFirstResponderChainDescription")
).takeUnretainedValue() as? String ?? "<Description Unavailable>"
}
}
@mayoff
Copy link

mayoff commented Mar 24, 2024

It's a little simpler to get the value with key-value coding:

self.value(forKey: "_eventFirstResponderChainDescription") as? String

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment