有人可以解释一下如何将值传递给使用时被拦截的不存在的方法:
+ (void)forwardInvocation:(NSInvocation *)anInvocation;
+ (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector;
给出如下消息:
[SomeClass doSomething:@"theThing" withSomething:@"aParam"];
我可以毫无问题地获取方法签名,但我对如何获取随其传递的值感到非常困惑。
我是否完全不知道何时应该使用这些方法,或者只是错过了一些东西?
-[NSInvocation getArgument:atIndex:] http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSInvocation_Class/Reference/Reference.html#//apple_ref/doc/uid/20000212-getArgument_atIndex_
所以在你的情况下,你会像这样使用它:
__unsafe_unretained NSString * firstArgument = nil;
__unsafe_unretained NSString * secondArgument = nil;
[theInvocation getArgument:&firstArgument atIndex:2];
[theInvocation getArgument:&secondArgument atIndex:3];
NSLog(@"Arguments: %@ and %@", firstArgument, secondArgument);
请记住self
and _cmd
是参数 0 和 1。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)