简体   繁体   English

发布时应删除调试代码(适用于iOS应用)

[英]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.

相关问题 ios对象在“调试”模式下释放,但不在“释放”模式下释放 - ios objects are released in Debug mode but not being released in Release mode 在调试模式下意外发布的 iOS 应用程序 - Accidentally released iOS app in debug mode 在调试或发布/分发模式下编译时,iOS应用程序的性能 - performance of iOS apps when compiling in debug or release / distribution mode 在iOS中调试生产应用程序吗? - Debug production in-apps in iOS? 是否在iOS应用程序中自动删除了文档目录? - Does the document directory is removed automatically in iOS apps? 与UITapGestureRecognizer结合使用时,UIScrollView子视图已释放(删除)内存 - UIScrollView subview is memory released (removed) when it's used in conjunction with UITapGestureRecognizer 现有已发布应用的 iOS 13 SDK 截止日期混淆 - iOS 13 SDK deadline confusion for existing released apps 什么时候应该删除NSUserNotificationCenter中的通知? - When should Notifications in the NSUserNotificationCenter be removed? 重启iOS设备时发布了什么? - What is released when restarting an iOS device? 是否应该在 iOS 中使用 removeObserver(self) 删除通知? - Should notifications be removed using removeObserver(self) in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM