[英]static method NSInvocation
是否可以将NSInvocation用于静态方法调用?
我们正在使用NSInvocation简化非公共方法的单元测试中的方法调用。
这对于我们的实例方法非常有用,为此我们为NSInvocation提供了一个对象和适当的数据。 但是,我们可以对静态方法做同样的事情吗?
是的你可以。 假设您的类是MyClass
而您的方法是+(void)myClassMethod:(id)sender;
, 您可以使用:
NSMethodSignature *signature = [MyClass methodSignatureForSelector:@selector(myClassMethod:)];
然后,可以在创建时向NSInvocation
提供NSMethodSignature
:
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.