I was using method swizzling to wrap all method invocations in a class with some extra functionality. Specifically I was:
I wanted to see if using NSProxy gave more readable code, plus thought NSProxy might make it easy to redirect method calls with an unknown number of arguments.
So, the NSProxy version works fine except for one important catch. Any internal calls on my sub-class don't go via the proxy.
Here's how I create the stand-in interceptor:
- (id)init
{
self = [super init];
if (self)
{
TyphoonAssemblyProxy* proxy = [[TyphoonAssemblyProxy alloc] initWithAssembly:self];
self = proxy; // 'self' should now be the proxy. . . but it seems not :(
}
return self;
}
Internal calls (ie calls to 'self' within the proxied class) don't get routed through proxy:
Now, in a sub-class of my proxied class, I have code want internal calls to go via the proxy. But they don't.
- (id)knight
{
return [TyphoonDefinition withClass:[Knight class] properties:^(TyphoonDefinition* definition)
{
//THIS NEXT CALL TO [self defaultQuest] SHOULD GO THROUGH PROXY MACHINERY!
[definition injectProperty:@selector(quest) withDefinition:[self defaultQuest]];
[definition injectProperty:@selector(damselsRescued) withValueAsText:@"12"];
[definition setScope:TyphoonScopeDefault];
}];
}
Question:
What is an easy way to get these internal goes to go via the proxy?
Instead of doing that maybe message forwarding would work for you.