Display log in debug and automatically block log output code in release. It took some time to combine the two NSLog optimization methods on the Internet.
The details are as follows:
1. Create a New. h file named DLog. h.
DLog. h file content:
// Add definition. No log is output during release.
# Ifndef _ OPTIMIZE __
# Define NSLog (...) NSLog (_ VA_ARGS __)
# Else
# Define NSLog (...){}
# Endif
Another
# Ifndef _ OPTIMIZE __
# Define DLog (...) NSLog (_ VA_ARGS __)
# Else
# Define DLog (...)
# Endif
# Define ALog (...) NSLog (_ VA_ARGS __)
2. Add to project.
Add the DLog. h header file to the appName-Prefix.pch.
After adding the file, the file is as follows:
# Import
# Ifndef _ IPHONE_3_0
# Warning "This project uses features only available in iPhone sdks 3.0 and later ."
# Endif
# Ifdef _ OBJC __
# Import
# Import
# Import "DLog. h"
# Endif
You can use DLog, ALog, or the NSLog that comes with the system.