Vote count:
0
I use NSProxy to mock a class, and want to hook all invocation of the class. But only methods called outside the class are hooked, without methods called inside the class. Below is something like my code:
In my AppDelegate.m, I call
TBClassMock *mock = [[TBClassMock alloc] init];
TBTestClass *foo = [[TBTestClass alloc] init];
mock.target = foo;
foo = mock;
[foo outsideCalled];
In my TBTestClass.m
- (void)outsideCalled
{
[self insideCalled];
}
- (void)insideCalled
{
}
In my TBClassMock.m
- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector
{
NSLog(@"Signature: %@", NSStringFromSelector(selector));
return [self.target methodSignatureForSelector:selector];
}
-(void)forwardInvocation:(NSInvocation*)anInvocation
{
//... Do other things
[anInvocation invokeWithTarget:self.target];
}
Then I can log the invocation of [foo outsideCalled]
, but can't log the invocation of [self insideCalled]
.
I aim to do something in all invocations of the class in //... Do other things
, and this way seems failed. Any explanations about this and any other method to implement my requirement? I just don't want to swizzle all methods of the class using method_exchangeImplementations
as I think it's too fussy and not a good way.
asked 21 secs ago
Aucun commentaire:
Enregistrer un commentaire