Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do we still need to hide/remove print statements in Xcode 8.2 and Swift 3 when releasing app?

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?

like image 898
crashoverride777 Avatar asked Mar 22 '17 12:03

crashoverride777


People also ask

Where are print statements in Xcode?

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.

What is print statement in Swift?

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()

How do I print in debug only in Swift?

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.

What is debug print in Swift?

debugPrint(_:separator:terminator:)Writes the textual representations of the given items most suitable for debugging into the standard output.


1 Answers

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
}
like image 153
crashoverride777 Avatar answered Oct 26 '22 16:10

crashoverride777