oc log的记录 宏的正确姿势

mac2022-06-30  20

参考:https://onevcat.com/2014/01/black-magic-in-macro/

#define NSLog(format, ...) do {                                                                          \

fprintf(stderr, "<%s : %d> %s\n",                                           \

[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String],  \

__LINE__, __func__);                                                        \

(NSLog)((format), ##__VA_ARGS__);                                           \

fprintf(stderr, "-------\n");                                               \

} while (0)

 

输出控件位置的正确姿势:

#define NSLogRect(rect) NSLog(@"%s x:%.4f, y:%.4f, w:%.4f, h:%.4f", #rect, rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)

#define NSLogSize(size) NSLog(@"%s w:%.4f, h:%.4f", #size, size.width, size.height)

#define NSLogPoint(point) NSLog(@"%s x:%.4f, y:%.4f", #point, point.x, point.y)

 

在log输出时慎用断言assert函数;

转载于:https://www.cnblogs.com/hazhede/p/8358586.html

最新回复(0)