在 Swift 2 之前,你可以通过像这样的小助手隐藏所有 println() 以供发布
func println(object: Any) {
#if DEBUG
Swift.println(object)
#endif
如果你把这个改成
func print(object: Any) {
#if DEBUG
Swift.print(object)
#endif
它按预期工作,但是 print() 具有新的 appendLine 功能。所以在你的代码中你可以写
println("Test", appendNewLine: false)
然而,这样做意味着上面提到的助手将不再工作。有关如何解决此问题的任何建议。非常感谢。
最佳答案
对于 swift 2.2,这是我使用的:
// Disable print for production.
func print(items: Any..., separator: String = " ", terminator: String = "\n") {
#if DEBUG
Swift.print(items[0], separator:separator, terminator: terminator)
#endif
}
关于Swift 2 print(),如何隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32439387/