I need to construct an arbitrary NSMethodSignature with "signatureWithObjCTypes:" in Cocoa without having an object that I can ask for a signature with "methodSignatureForSelector:".
For this, I need the method encoding, which e.g. is
c12@0:4@8
for
(BOOL) isEqual: (id) object
I tried @encode(...) to obtain a type encoding, but this does not seem to work for functions (it results in an unknown type '?'). I dont't want to manually encode the function type, since this is not portable across different runtimes.
There also is no declared method to obtain the encoding from.
Is there another way of obtaining the encoding?
Regards,
Jochen
What about something like:
#import <objc/runtime.h>
//inside the method implementation:
Method thisMethod = class_getClassMethod([self class], _cmd);
const char * encoding = method_getTypeEncoding(thisMethod);
Or for an arbitrary method:
#import <objc/runtime.h>
//inside the method implementation:
Method thisMethod = class_getClassMethod([self class], @selector(isEqual:));
const char * encoding = method_getTypeEncoding(thisMethod);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With