字符串相互转换打印

1.在非调试状态下NSLog不工作

#ifdef DEBUG
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...)
#endif

2.去掉打印的时间戳

#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s
",[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif

3.不同颜色的打印

#ifdef DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"%s:%d	%s
",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(...)
#endif

4.unicode转换成中文

#define NSLog(format, ...) NSLog(format, ## __VA_ARGS__)

5.结构体转化为字符串打印

    CGRect rect = CGRectMake(0.0, 0.0, 320.0, 460.0);

    NSString *str = NSStringFromCGRect(rect); //结构体转化为字符串

    NSLog(@"%@",str);

    //CGRectFromString(str); //字符串转化为结构体
原文地址:https://www.cnblogs.com/shen5214444887/p/4826518.html