因为NSLog的输出还是比较消耗系统资源的,而且输出的数据也可能会暴露出App里的保密数据,所以发布正式版时需要把这些输出全部屏蔽掉。
我们可以在发布版本前先把所有NSLog语句注释掉,等以后要调试时,再取消这些注释,这实在是一件无趣而耗时的事!还好,还有更优雅的解决方法,就是在项目的prefix.pch文件里加入下面一段代码,加入后,NSLog就只在Debug下有输出,Release下不输出了。【以下任意一种均可】
第一种:
- #ifndef __OPTIMIZE__
- #define NSLog(...) NSLog(__VA_ARGS__)
- #else
- #define NSLog(...) {}
-
#endif
第二种:
- #ifndef __IPHONE_4_0
- #warning "This project uses features only available in iOS SDK 4.0 and later."
- #endif
- #ifdef __OBJC__
- #import <UIKit/UIKit.h>
- #import <Foundation/Foundation.h>
- #import "AppDelegate.h"
- #import "UIViewController+Customized.h"
-
#endif
-
#ifndef __OPTIMIZE__
- #define NSLog(...) NSLog(__VA_ARGS__)
-
#else
- #define NSLog(...) {}
- #endif