Skip to content

Instantly share code, notes, and snippets.

@ap4y
Last active December 15, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ap4y/5305500 to your computer and use it in GitHub Desktop.
Save ap4y/5305500 to your computer and use it in GitHub Desktop.
Instance method invocation logger
UIBezierPath *apath = [UIBezierPath bezierPath];
InvocationLogger *logger = [InvocationLogger new];
logger.interceptedTarget = aPath;
aPath = (UIBezierPath *)logger;
[aPath moveToPoint:CGPointMake(15.3f, 7.6f)];
/**
* Result:
* 2013-04-04 10:20:53.719 svg_test[98065:c07] [path moveToPoint:{15.3, 7.6}]
**/
@interface InvocationLogger : NSObject
@property (strong, nonatomic) id interceptedTarget;
@end
@implementation InvocationLogger
- (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector {
return [_interceptedTarget methodSignatureForSelector:aSelector];
}
- (void)forwardInvocation:(NSInvocation *)anInvocation {
CGPoint firstArg;
[anInvocation getArgument:&firstArg atIndex:2];
NSLog(@"[path %@%@]", NSStringFromSelector([anInvocation selector]), NSStringFromCGPoint(firstArg));
[anInvocation invokeWithTarget:_interceptedTarget];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment