Skip to content

Instantly share code, notes, and snippets.

@interstateone
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save interstateone/2bdcae4dead0f59470a6 to your computer and use it in GitHub Desktop.
Save interstateone/2bdcae4dead0f59470a6 to your computer and use it in GitHub Desktop.
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