从NSInvocation获取参数值 [英] Getting argument values from NSInvocation
本文介绍了从NSInvocation获取参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以解释如何获取传递给不存在的方法使用时被拦截的方法:
Could someone please explain how to go about getting the values passed to a non-existant method that is being intercepted when using:
+ (void)forwardInvocation:(NSInvocation *)anInvocation;
+ (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
给出如下消息:
[SomeClass doSomething:@"theThing" withSomething:@"aParam"];
我可以得到方法签名没有问题,但我非常困惑的如何获取值被传入与它。
I can get the method signature without a problem but I am terribly confused about how to get the values that were passed in with it.
当我应该使用这些方法或者只是缺少某些东西时,我是否完全禁用?
Am I totally off base in when I should use these methods or just missing something?
推荐答案
- [NSInvocation getArgument:atIndex:]
所以在你的case,你会使用它像:
So in your case, you would use it like:
__unsafe_retained NSString * firstArgument = nil;
__unsafe_retained NSString * secondArgument = nil;
[theInvocation getArgument:&firstArgument atIndex:2];
[theInvocation getArgument:&secondArgument atIndex:3];
NSLog(@"Arguments: %@ and %@", firstArgument, secondArgument);
请记住, self
和 _cmd
是参数0和1。
Remember that self
and _cmd
are arguments 0 and 1.
这篇关于从NSInvocation获取参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文