Disable print when build release scheme in Xcode with swift

Under what circumstances?

  • Under Xcode 12.2
  • With Swift5

How to do?

It’s very simple way to be disable print function.

If you are developing using Swift, it doesn’t matter which swift file. Please insert the code below. In my case, I inserted it at the top of the AppDelegate.

import UIKit
import CoreData
...

func print(_ items: Any...) {
    #if DEBUG
        Swift.print(items[0])
    #endif
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
...

After insert codes, please change build scheme environment debug to release. follow below image.

image

If you need print again, changed scheme to debug.

Conclusion

Override function is very useful when i develop application by swift

Stay Hunger, Stay Foolish