Getting type encodings for method signatures in Cocoa / Objective-C?

I need to build an arbitrary NSMethodSignature with "signatureWithObjCTypes:" in Cocoa without an object that I can ask for a signature using methodSignatureForSelector :.

For this, I need a method encoding, which, for example,

c12@0:4@8

for

(BOOL) isEqual: (id) object

I tried @encode (...) to get the type encoding, but this does not work for functions (this leads to an unknown type '?'). I do not want to manually encode the type of the function, since it is not portable in different time modes.

There is also no declared method to get the encoding.

Is there any other way to get the encoding?

Yours faithfully,

Jochen

+5
source share
2

- :

#import <objc/runtime.h>
//inside the method implementation:
Method thisMethod = class_getClassMethod([self class], _cmd);
const char * encoding = method_getTypeEncoding(thisMethod);

:

#import <objc/runtime.h>
//inside the method implementation:
Method thisMethod = class_getClassMethod([self class], @selector(isEqual:));
const char * encoding = method_getTypeEncoding(thisMethod);
+12

?

? | ( , )

AFAIK , . , , int.

0

All Articles