xcode로 cocoa(Objective-C) 프로그램 제작 중.
디버그 매크로가 필요해서 작성했습니다.
필요 하신 분들은 참고 하세요.
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Debug
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DEBUG_ON 1 // 0 : Debug Off, 1 : Debug On
#if DEBUG_ON
#define debug(format, ...) NSLog(format, ## __VA_ARGS__);
#define DEBUG(format, ...) NSLog(@"[%s:%d:%s] : %@", \
[[[[NSString alloc] initWithBytes:__FILE__ length:strlen(__FILE__) encoding:NSUTF8StringEncoding] lastPathComponent] UTF8String] ,\
__LINE__, __FUNCTION__, [NSString stringWithFormat:format, ## __VA_ARGS__]);
#else
#define debug(format, ...)
#define DEBUG(format, ...)
#endif
#define debugRect(rect) debug(@"%s x:%.4f, y:%.4f, w:%.4f, h%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define debugSize(size) debug(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define debugPoint(point) debug(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
// Debug
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DEBUG_ON 1 // 0 : Debug Off, 1 : Debug On
#if DEBUG_ON
#define debug(format, ...) NSLog(format, ## __VA_ARGS__);
#define DEBUG(format, ...) NSLog(@"[%s:%d:%s] : %@", \
[[[[NSString alloc] initWithBytes:__FILE__ length:strlen(__FILE__) encoding:NSUTF8StringEncoding] lastPathComponent] UTF8String] ,\
__LINE__, __FUNCTION__, [NSString stringWithFormat:format, ## __VA_ARGS__]);
#else
#define debug(format, ...)
#define DEBUG(format, ...)
#endif
#define debugRect(rect) debug(@"%s x:%.4f, y:%.4f, w:%.4f, h%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define debugSize(size) debug(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define debugPoint(point) debug(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
참고 사이트를 보면, CFShow로 콘솔창에 출력을 할 수도 있습니다. 날짜시간과 어플리케이션도 출력하지 않고 깔끔하게 출력해 줍니다.
하지만, CFShow는 UTF8을 지원하지 않아서, 한글 출력에 문자가 있더군요 ㅜ.ㅜ
그래서 위와 같이 제작을 했습니다.
혹시, 난 영어 잘 해서, 디버깅 할 때 한글 필요 없다 하시는 분들은, 아래 코드를 사용하세요 ^^*
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Debug
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DEBUG_ON 1 // 0 : Debug Off, 1 : Debug On
#if DEBUG_ON
#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
#define DEBUG(format, ...) CFShow([NSString stringWithFormat:@"[%@:%d:%s:%@]", \
[[[NSString alloc] initWithBytes:__FILE__ length:strlen(__FILE__) encoding:NSUTF8StringEncoding] lastPathComponent] ,\
__LINE__, __FUNCTION__, [NSString stringWithFormat:format, ## __VA_ARGS__]]);
#else
#define debug(format, ...)
#define DEBUG(format, ...)
#endif
#define debugRect(rect) debug(@"%s x:%.4f, y:%.4f, w:%.4f, h%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define debugSize(size) debug(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define debugPoint(point) debug(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
// Debug
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#define DEBUG_ON 1 // 0 : Debug Off, 1 : Debug On
#if DEBUG_ON
#define debug(format, ...) CFShow([NSString stringWithFormat:format, ## __VA_ARGS__]);
#define DEBUG(format, ...) CFShow([NSString stringWithFormat:@"[%@:%d:%s:%@]", \
[[[NSString alloc] initWithBytes:__FILE__ length:strlen(__FILE__) encoding:NSUTF8StringEncoding] lastPathComponent] ,\
__LINE__, __FUNCTION__, [NSString stringWithFormat:format, ## __VA_ARGS__]]);
#else
#define debug(format, ...)
#define DEBUG(format, ...)
#endif
#define debugRect(rect) debug(@"%s x:%.4f, y:%.4f, w:%.4f, h%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)
#define debugSize(size) debug(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)
#define debugPoint(point) debug(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)
뭐.. 필요 하신 분들은 대충 섞어서, 한글용, 영문용으로 합쳐서 사용하셔도 되겠네요 ^^;
참고 :
- Debugging Macros
- Yet Another Debug Output (NSLog Replacement)
- Xcode Debugging: Going Back in Time
- Filename and Line Number with NSLog: Part I
- Filename and Line Number with NSLog: Part II
댓글