title: How to get a selector of a class method?
body: <p>I have the next code where I am getting a pointer to instance method:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;objc/runtime.h&gt;
  
  @interface TestClass : NSObject
  @end
  
  @implementation TestClass
  - (void)someMethod { // This is instance method, it's okay
    NSLog(@"Hello from some method!");
  }
  @end
  
  int main(int argc, const char * argv[]) {
    typedef void (*MethodWithoutParams)();
    MethodWithoutParams someMethodImplementation = 
  class_getMethodImplementation([TestClass class], @selector(someMethod));
    someMethodImplementation();
    return 0;
  }
  </code></pre>
  
  <p>It works pretty good. But if I'd like to get a pointer to class method, it doesn't work:</p>
  
  <pre><code>#import &lt;Foundation/Foundation.h&gt;
  #import &lt;objc/runtime.h&gt;
  
  @interface TestClass : NSObject
  @end
  
  @implementation TestClass
  + (void)someMethod { // This is class method, it doesn't work
    NSLog(@"Hello from some method!");
  }
  @end
  
  int main(int argc, const char * argv[]) {
    typedef void (*MethodWithoutParams)();
    MethodWithoutParams someMethodImplementation = 
  class_getMethodImplementation([TestClass class], @selector(someMethod));
    someMethodImplementation();
    return 0;
  }
  </code></pre>
  
  <p>It doesn't work because it can not look up the method implementation.</p>
  
  <p>I am sure it <strong>must</strong> work, because it works if I am getting the implementation in such way:</p>
  
  <pre><code>MethodWithoutParams someMethodImplementation = 
  [TestClass methodForSelector:@selector(someMethod)];
  </code></pre>
  
  <p>So I looked into NSObject implementation and see the next code:</p>
  
  <pre><code>+ (IMP)methodForSelector:(SEL)sel {
      if (!sel) [self doesNotRecognizeSelector:sel];
      return object_getMethodImplementation((id)self, sel);
  }
  
  - (IMP)methodForSelector:(SEL)sel {
      if (!sel) [self doesNotRecognizeSelector:sel];
      return object_getMethodImplementation(self, sel);
  }
  </code></pre>
  
  <p>Also <code>object_getMethodImplementation()</code> function <a href="http://www.opensource.apple.com/source/objc4/objc4-646/runtime/objc-class.mm" rel="nofollow">has</a> the next implementation:</p>
  
  <pre><code>IMP object_getMethodImplementation(id obj, SEL name)
  {
      Class cls = (obj ? obj-&gt;getIsa() : nil);
      return class_getMethodImplementation(cls, name);
  }
  </code></pre>
  
  <p>So the implementation is same for both class method lookup and instance method lookup.</p>
  
  <p>But it doesn't work and I have no idea why. I guess that any type of methods (both class and instance) gonna be located in the dispatch table, and I can get the pointer to any of this methods. But as you see I can't do it.</p>