Last active
December 15, 2015 18:39
-
-
Save ap4y/5305500 to your computer and use it in GitHub Desktop.
Instance method invocation logger
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}] | |
**/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface InvocationLogger : NSObject | |
@property (strong, nonatomic) id interceptedTarget; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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