Created
November 21, 2023 11:45
-
-
Save paweldudek/e8646f5a214a562306f66fc9cbf37dcc to your computer and use it in GitHub Desktop.
Swift Class Dump Helpers
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
let actionClass: AnyClass = NSClassFromString("_UIImmutableAction")! | |
let functions = dumpFunctions(anyClass: actionClass) | |
let vars = dumpVars(anyClass: actionClass) | |
if let superclass = class_getSuperclass(actionClass) { | |
let functions = dumpFunctions(anyClass: superclass) | |
let vars = dumpVars(anyClass: superclass) | |
} | |
func dumpFunctions(anyClass: AnyClass) -> [Selector] { | |
var methodCount: UInt32 = 0 | |
let methodList = class_copyMethodList(anyClass, &methodCount)! | |
return (0 ..< Int(methodCount)).compactMap({ method_getName(methodList[$0]) }) | |
} | |
func dumpVars(anyClass: AnyClass) -> [String] { | |
var varsCount: UInt32 = 0 | |
guard let varsList = class_copyIvarList(anyClass, &varsCount) else { return [] } | |
return (0 ..< Int(varsCount)).compactMap({ ivar_getName(varsList[$0]) }).map({ String(cString: $0) }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment