Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if class has static method

Tags:

objective-c

We can easily check if object has a method by using respondsToSelector:, but how we do it for static functions in class?

I would like to have something like this:

if ([cls classRespondsToSelector:@selector(staticMethodName)]) {
    ...
}
like image 676
ivanzoid Avatar asked Feb 27 '12 09:02

ivanzoid


1 Answers

In Objective-C classes are objects too.

if ([[myClass class] respondsToSelector:@selector(classMethod)]) {

}

Also a small note, these are NOT 'static' methods. That means something specific which doesn't exist in Objective-C. They are class methods.

like image 160
Joshua Weinberg Avatar answered Oct 05 '22 07:10

Joshua Weinberg