banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

Disable NSLog during iOS development to prevent it from being displayed on the console during release.

In iOS development, the most commonly used method to record logs is by using the NSLog() function. By default, NSLog() will output logs to the console during debugging. However, when the app is released, we don't need to display the logs anymore. In this case, the strategy is to either not display the logs or write them to a log file.

You can directly disable NSLog and prevent it from displaying on the console using the following method.

//
// Close all NSLog()
//
#ifdef OPTIMIZE

define NSLog(...) {}#

#else

define NSLog(...) NSLog(VA_ARGS)#

#endif

The above method mainly utilizes the OPTIMIZE option of the Objective-C compiler. It defines OPTIMIZE in Release mode, but not in Debug mode.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.