Skip to content

Instantly share code, notes, and snippets.

@claybridges
Created January 28, 2013 20:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claybridges/4658680 to your computer and use it in GitHub Desktop.
Save claybridges/4658680 to your computer and use it in GitHub Desktop.
Objective-C ProtocolContainsInstanceSelector
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