Created
January 28, 2013 20:24
-
-
Save claybridges/4658680 to your computer and use it in GitHub Desktop.
Objective-C ProtocolContainsInstanceSelector
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BOOL ProtocolContainsInstanceSelector(NSString *protocolName, SEL sel); | |
BOOL ProtocolContainsInstanceSelector(NSString *protocolName, SEL sel) | |
{ | |
Protocol *p = objc_getProtocol([protocolName cStringUsingEncoding:NSUTF8StringEncoding]); | |
// must check for both required = {YES, NO} | |
struct objc_method_description desc = protocol_getMethodDescription(p, sel, YES, YES); | |
BOOL contains = desc.name != NULL && desc.types != NULL; | |
if (!contains) { | |
desc = protocol_getMethodDescription(p, sel, NO, YES); | |
contains = desc.name != NULL && desc.types != NULL; | |
} | |
return contains; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment