Is it possible to use NSInvocation for static method calls?
We're using NSInvocation to simplify our method calls in unit tests for non-public methods.
This works great for our instance methods, for which we provide an object and appropriate data to NSInvocation. However, can we do the same with static methods?
Yes, you can. Assuming your class is MyClass
and your method is +(void)myClassMethod:(id)sender;
, you can use:
NSMethodSignature *signature = [MyClass methodSignatureForSelector:@selector(myClassMethod:)];
Then you can provide the NSMethodSignature
to your NSInvocation
when created:
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.