具体如下:
一、新建一个.h文件,命名为DLog.h。
DLog.h文件内容为:
//添加定义,在release时不会输出log
#ifndef __OPTIMIZE__
#define NSLog(...) NSLog(__VA_ARGS__)
#else
#define NSLog(...) {}
#endif
另一种
#ifndef __OPTIMIZE__
#define DLog(...) NSLog(__VA_ARGS__)
#else
#define DLog(...)
#endif
#define ALog(...) NSLog(__VA_ARGS__)
二、添加到工程。
在appName-Prefix.pch中添加DLog.h头文件。
添加后如下所示:
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iPhone SDK 3.0 and later."
#endif
#ifdef __OBJC__
#endif
通过这样定义,既可以用DLog,ALog,也可以使用系统自带的NSLog。
原文:http://blog.csdn.net/learnios/article/details/18966309