Skip to content

Instantly share code, notes, and snippets.

@hcrub
Last active April 9, 2020 14:39
Show Gist options
  • Save hcrub/7358358 to your computer and use it in GitHub Desktop.
Save hcrub/7358358 to your computer and use it in GitHub Desktop.
Objective C Runtime's class_respondsToSelector to detect if whether instances of a class respond to a particular selector.
/**
* class_respondsToSelector
* Returns a Boolean value that indicates whether instances of a class respond to a particular selector.
* Overall, class_respondsToSelector looks up the selector in the class's method table to see if it has an entry
*
* BOOL class_respondsToSelector(Class cls, SEL sel)
*
* Parameters
* cls
* The class you want to inspect.
*
* sel
* A selector.
*
* Return Value
* YES if instances of the class respond to the selector, otherwise NO.
*
* Warning
* You should usually use NSObject's respondsToSelector: or instancesRespondToSelector: methods instead of this function.
*
**/
- (BOOL)respondsToSelector: (SEL)aSelector
{
return class_respondsToSelector(isa, aSelector);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment