Last active
March 28, 2024 19:52
-
-
Save usagimaru/25c4655da6be4a9b0d1c33cf23f9dd8c to your computer and use it in GitHub Desktop.
Get all methods of an class or instance in Swift
This file contains hidden or 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
// Dump all NSApplication’s class methods | |
let dump = NSApplication.perform(NSSelectorFromString("fp_methodDescription")).takeUnretainedValue() as? String | |
// Dump all NSApplication’s instance methods | |
let dump = NSApp.perform(NSSelectorFromString("fp_methodDescription")).takeUnretainedValue() as? String | |
// or | |
print(NSApplication.value(forKey: "fp_methodDescription")) | |
print(NSApp.value(forKey: "fp_methodDescription")) | |
// "fp_methodDescription" for AppKit | |
// "_methodDescription" for UIKit | |
// "fp_ivarDescription" for ivar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
References:
https://stackoverflow.com/questions/2094702/get-all-methods-of-an-objective-c-class-or-instance
https://x.com/stephancasas/status/1769831710915539224
https://mjtsai.com/blog/2024/03/22/_eventfirstresponderchaindescription/
https://christiantietze.de/posts/2023/06/swiftui-onsubmit/