2016年7月29日 星期五

如何讓nslog在release之後不見


網址:

https://github.com/web8246/TestNSLogWhenRelease.git

第一步,先新創一個pch檔案:



之後在裡面新增上:

#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"[文件名:%s]\n" "[函数名:%s]\n" "[行号:%d] \n" fmt), __FILE__, __FUNCTION__, __LINE__, ##__VA_ARGS__);
#define DeBugLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#define NSLog(...) NSLog(__VA_ARGS__);
#define MyNSLog(FORMAT, ...) fprintf(stderr,"[%s]:[line %d] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define DLog(...)
#define DeBugLog(...)
#define NSLog(...)
#define MyNSLog(FORMAT, ...) nil

#endif

當設置好之後,要讓xcode找的到他,知道要去使用這個pch檔案:


然後,再來看看如何設置在模擬器要使用debug模式或是release:


















確定有設置好下面的條件,這樣才會去自動幫你改nslog:


1."Target > Build Settings > Preprocessor Macros > Debug" 里有一个"DEBUG=1",这保证了我们的条件编译的"#if"可以编译。如果没有,请自行添加,注意和代码中的#if后面的字段保持一致。

沒有留言:

張貼留言