Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Comparing the output of protocol_getMethodDescription and _protocol_getMethodTypeEncoding
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
const char *_protocol_getMethodTypeEncoding(Protocol *, SEL, BOOL isRequiredMethod, BOOL isInstanceMethod);
@protocol Tester <NSObject>
@required
- (BOOL)testDictionary:(NSDictionary *)dictionary error:(NSError **)error;
@end
int main(int argc, char *argv[]) {
@autoreleasepool {
struct objc_method_description description = protocol_getMethodDescription(@protocol(Tester), @selector(testDictionary:error:), YES, YES);
NSLog(@"%s", description.types);
// Outputs c32@0:8@16^@24
const char *descriptionString = _protocol_getMethodTypeEncoding(@protocol(Tester), @selector(testDictionary:error:), YES, YES);
NSLog(@"%s", descriptionString);
// Outputs c32@0:8@"NSDictionary"16^@24
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment