Created
August 20, 2025 13:55
-
-
Save berikv/310b493f837a93b693af7c1bef2969d3 to your computer and use it in GitHub Desktop.
Print the type signature of an objc method found in the runtime
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
| import ObjectiveC.runtime | |
| private func dumpMethodSignature(_ clsName: String, _ selName: String) { | |
| let cls: AnyClass = NSClassFromString(clsName)! | |
| let sel = NSSelectorFromString(selName) | |
| let m = class_getInstanceMethod(cls, sel)! | |
| let nargs = method_getNumberOfArguments(m) | |
| let ret = String(cString: method_copyReturnType(m)) | |
| let enc = method_getTypeEncoding(m).map { String(cString: $0) } ?? "?" | |
| print("== \(clsName) \(selName)") | |
| print(" encoding: \(enc)") | |
| print(" return: \(ret)") | |
| print(" args (\(nargs)):") | |
| for i in 0..<nargs { | |
| if let t = method_copyArgumentType(m, i) { | |
| print(" [\(i)] \(String(cString: t))") | |
| free(t) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment