xcode 从发布版本中删除 NSLog

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12798582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:44:55  来源:igfitidea点击:

Remove NSLog from Release Builds

objective-ciosxcode

提问by Nishan29

Possible Duplicate:
Is it true that one should not use NSLog() on production code?
Do I need to disable NSLog before release Application?

可能的重复:
真的不应该在生产代码上使用 NSLog() 吗?
我需要在发布应用程序之前禁用 NSLog 吗?

I need to remove all the NSLOGs which are present in my project during the Release build. I have tried using the below code , but still accessing the build via phone, still NSLOG shows up in the console.

我需要在发布版本期间删除我的项目中存在的所有 NSLOG。我已尝试使用以下代码,但仍通过电话访问构建,但 NSLOG 仍显示在控制台中。

#ifdef DEBUG
#define debug_NSLog(format, ...) NSLog(format, ## __VA_ARGS__)
#else
#define debug_NSLog(format, ...)
#endif

回答by Stas

To simply remove NSLogs:

简单地删除 NSLogs:

#define NSLog(s,...)

A #definewithout a substitution specified will substitute nothing, deleting anything that matches that #define. This works with simple token defines and with function-like defines like the above.

#define没有指定替换的A将不替换任何内容,删除与该 匹配的任何内容#define。这适用于简单的令牌定义和类似函数的定义,如上述。

回答by zahreelay

Use the following code

使用以下代码

#ifdef DEBUGGING
# define DBLog(fmt,...) NSLog(@"%@",[NSString stringWithFormat:(fmt), ##__VA_ARGS__]);
#else
# define DBLog(...)
#endif 

Make sure the compiler flags are properly set.

确保正确设置编译器标志。

Also, when you checked the console, did you check if you were using release mode ?

另外,当您检查控制台时,您是否检查过是否使用了发布模式?

回答by Mehul Mistri

Use this

用这个

#if TARGET_IPHONE_SIMULATOR
#define NSLog(fmt,...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define NSLog(...)
#endif

This will print NSLogif you are running it on simulator..

NSLog如果您在模拟器上运行它,这将打印..