I am trying to get a signature - either an NSMethodSignature object, or at least a type encoding string - for a method declared in the protocol.
Requesting a Protocol object is not possible, because a) it does not implement methodSignatureForSelector: and b) (as Kevin noted below), it is deprecated.
The protocol_getMethodDescription runtime function returns a struct objc_method_description that is not described elsewhere in the documents. This is in the public header, however - <objc / runtime.h> :
struct objc_method_description { SEL name; char *types; };
It seems reasonable to assume that the types string there will be the same signature encoding string used elsewhere, such as expected with +[NSMethodSignature signatureWithObjCTypes:] , and indeed, it looks correct.
What I cannot keep track of is the real, testable connection between this string and the type coding process.
I canβt think what else would happen, but do I have every reason to rely on this types line to be valid for interacting with other objects / functions in the same work ? Please note that I myself do not write coding strings or do not expect them to have the specified format or value. I only want to transfer them from one part of the runtime to another, i.e. Get the encoding string from the protocol and) use it to generate the NSMethodSignature object, if it is not otherwise available, and, possibly, b) compare it with the version of NSInvocation created at run time (i.e. in -forwardInvocation: .
source share