Skip to content

Instantly share code, notes, and snippets.

@usagimaru
Last active March 28, 2024 19:52
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usagimaru/25c4655da6be4a9b0d1c33cf23f9dd8c to your computer and use it in GitHub Desktop.
Save usagimaru/25c4655da6be4a9b0d1c33cf23f9dd8c to your computer and use it in GitHub Desktop.
Get all methods of an class or instance in Swift
// 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