开发者

Getting argument values from NSInvocation

开发者 https://www.devze.com 2022-12-19 02:48 出处:网络
Could someone please explain how to go about getting the values passed to a non-existant method that is being intercepted when using:

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;

Given a message like:

[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开发者_StackOverflow.

Am I totally off base in when I should use these methods or just missing something?


-[NSInvocation getArgument:atIndex:]

So in your case, you would use it like:

__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);

Remember that self and _cmd are arguments 0 and 1.

0

精彩评论

暂无评论...
验证码 换一张
取 消