|
| 1 | +#import <Foundation/Foundation.h> |
| 2 | + |
| 3 | +NS_ASSUME_NONNULL_BEGIN |
| 4 | + |
| 5 | +@interface SSYMethodSignatureDumper : NSObject |
| 6 | + |
| 7 | +/*! |
| 8 | + @brief Dumps to the console a nice description of the Objective-C method |
| 9 | + signature for a given method |
| 10 | +
|
| 11 | + @details Although this method is Objective-C, it is used in Swift code. |
| 12 | + It is useful if you need to see the Objective-C method signature of a method |
| 13 | + when debugging code from a Swift file, because Swift does not expose |
| 14 | + NSMethodSignature. Import this file in your Swift-Bridging-Header.h |
| 15 | +
|
| 16 | + Here are 4 examples of how to invoke this method in Swift: |
| 17 | +
|
| 18 | + MethodSignatureDumper.dumpMethodSignature(forTarget:self, selector:#selector(self.agentBundleIdentifier)) |
| 19 | + MethodSignatureDumper.dumpMethodSignature(forTarget:self, selector:#selector(GUIAppDel.loginItemSwitch(on:))) |
| 20 | + MethodSignatureDumper.dumpMethodSignature(forTarget:agentProxy, selector:#selector(Worker.getVersionThenDo(_:))) |
| 21 | + MethodSignatureDumper.dumpMethodSignature(forTarget:agentProxy, selector:#selector(Worker.doWork(on:thenDo:))) |
| 22 | +
|
| 23 | + In #selector(), the prefixes "self." and "GUIAppDel." are equivalent. These |
| 24 | + prefixes are optional if the target method is in a class, but required |
| 25 | + if the target method is in a protocol, and in that case the protocol name, |
| 26 | + for example, "Worker", must be used explicitly. |
| 27 | +
|
| 28 | + In the output log entry, in the list of arguments, argument 0 is the message |
| 29 | + receiver and argument 1 is the selector (method). Argument types are given as |
| 30 | + encoded as "type codes". To decode, look up the codes in Apple's |
| 31 | + Objective-C Runtime Programming Guide > Type Encodings |
| 32 | + https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100 |
| 33 | + */ |
| 34 | ++ (void)dumpMethodSignatureForTarget:(id)target |
| 35 | + selector:(SEL)selector; |
| 36 | + |
| 37 | +@end |
| 38 | + |
| 39 | +NS_ASSUME_NONNULL_END |
0 commit comments