简体   繁体   English

静态方法NSInvocation

[英]static method NSInvocation

Is it possible to use NSInvocation for static method calls? 是否可以将NSInvocation用于静态方法调用?

We're using NSInvocation to simplify our method calls in unit tests for non-public methods. 我们正在使用NSInvocation简化非公共方法的单元测试中的方法调用。

This works great for our instance methods, for which we provide an object and appropriate data to NSInvocation. 这对于我们的实例方法非常有用,为此我们为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; 假设您的类是MyClass而您的方法是+(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提供NSMethodSignature

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM