How can I invoke a class method by NSInvocation?

objective-c

Solution

You can get the class methods by:

NSMethodSignature *pMS = [[YourObject class] methodSignatureForSelector: (SEL)aSelector];

The fragment `[YourObject class]` returns an instance of the class object (singleton) which you can then use to get class methods.

ADD: New info from comments below. You can just do the following:

NSMethodSignature *pMS = [YourObject methodSignatureForSelector: (SEL)aSelector];

Problem

We can get `NSMethodSignature` by `+ (NSMethodSignature *)instanceMethodSignatureForSelector:(SEL)aSelector` of `NSObject`. Then construct `NSInvocation` by `+ (NSInvocation *)invocationWithMethodSignature:(NSMethodSignature *)signature` Here is the problem. We can only get the method signature of instance,how about the class method?

Original source