Remove println() for release version iOS Swift

前端 未结 19 1510
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 15:55

I would like to globally ignore all println() calls in my Swift code if I am not in a Debug build. I can\'t find any robust step by step instructions for this a

19条回答
  •  日久生厌
    2020-11-29 16:49

    Swift 4 Xcode 10.0

    maybe you could use this

    func dPrint(_ message: @autoclosure () -> Any) {
        #if DEBUG
        print(message())
        #endif
    }
    

    The reason of using @autoclosure is that if you pass a function as the message parameter, the function will be called only in debug mode, it will cause a performance hit.

    unlike the Swift.print(_ items: Any..., separator: String = default, terminator: String = default) function, my solution has only one parameter, because in most cases, we don't pass multiple parameters as the print function only shows information in console, we can just convert the parameters to String: "\(param1)"+"\(param2)", right? hope u like my solution

提交回复
热议问题