[英]Should debug code be removed when released (for iOS apps)
I am currently making an application using swift where I am using some debug code. 我目前正在使用Swift编写应用程序,而我正在使用一些调试代码。
Here is my logic: 这是我的逻辑:
//Do some code that always gets executed
if self.debug
{
//Do some debugging code
}
//Do more code that always gets executed
When I put this for release, should I remove the debug code or could I just set self.debug to false? 当我发布它时,应该删除调试代码还是可以将self.debug设置为false?
I have looked at this question: Should debugging code be left in place? 我看了这个问题: 是否应将调试代码保留在原处? , however that sounds like it's to give the user choice if they want to debug the application or not, with iOS applications users cannot debug it unless they have the Xcode project. ,但这听起来像是要让用户选择是否调试应用程序,对于iOS应用程序,用户除非拥有Xcode项目,否则无法对其进行调试。
Preprocessor directives are a more preferable way of marking code that should only be compiled for debug builds. 预处理程序指令是标记代码的更可取的方式,该代码仅应为调试版本编译。
#if DEBUG
// Do debug things
#endif
By using preprocessor directives, the code that you put in that block doesn't get compiled into release builds. 通过使用预处理程序指令,您放入该块中的代码不会被编译到发行版本中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.