【发布时间】:2009-11-29 02:26:23
【问题描述】:
我想通过打印选择器和参数来拦截发送到代理对象的消息。即使代理没有实现它们并且没有目标对象。请帮忙。我查看了几个选项和 Apple 文档,但他们假设您已经知道目标对象。我想干净地做到这一点,没有内存问题。
@implementation MyProxy
-(void)forwardInvocation:(NSInvocation*)anInvocation
{
// at this point I would
//like to fetch the arguments and put on an array
NSMutableArray *myArgs = .....;
NSLog(@"Invoking selector %@", theSelector);
NSLog (myArgs); // this should print me the list of arguments to the method
}
@end
// e.g
MyProxy *proxy = [[MyProxy alloc] init];
[proxy SendMeAnyThing: @"hello"]; // this should print me arguments
or [proxy add: 12 to: 89 sub: 89]; // should print the arguments
感谢感谢
【问题讨论】:
标签: iphone objective-c cocoa proxy-classes objective-c-runtime