Is it still recommended / needed to hide print statements when releasing an app with Xcode 8.2 and Swift 3?
At the moment I have a global print function like this
func print(_ items: Any...) {
#if DEBUG
Swift.print(items[0])
#endif
}
than will only print if the project is in Debug mode.
Apple recently finally added the DEBUG flag by default in Xcode so we do not have to manually add it anymore in OtherFlags in Build Settings.
This made me wonder if we actually still need to remove the print statements or does Swift/Xcode do it automatically or is there some other optimisation where it is no longer needed.
If not is the above way the best approach?
Press ⇧⌘Y or choose View > Debug Area > Show Debug Area to show the console output (or ⇧⌘C / Activate Console). Usually, this window will open automatically when your program produces output (this is controlled by the Behaviors section of Xcode's Preferences). Save this answer. Show activity on this post.
In Swift, we can simply use the print() function to print output. For example, print("Swift is powerful") // Output: Swift is powerful. Here, the print() function displays the string enclosed inside the double quotation. Syntax of print()
Swift Print() Only in Debug Mode? Basically print() function is used to write text to the Xcode debug console in Swift. It helps to debug the code. The print() function is actually variadic, so you can pass it more than one parameter and it will print them all.
debugPrint(_:separator:terminator:)Writes the textual representations of the given items most suitable for debugging into the standard output.
After doing some more research it still seems that we need/should hide print statements for release. As mentioned in my question its best done via a global print function
func print(_ items: Any...) {
#if DEBUG
Swift.print(items[0])
#endif
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With