在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)然而,这样做意味着上面提到的助手将不再工作。关于如何解决这个问题的任何建议。非常感谢。
发布于 2016-08-31 15:58:53
对于SWIFE2.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
}发布于 2015-09-07 13:12:16
使用Swift.debugPrint()关闭发布模式下的所有打印。
发布于 2015-09-07 13:24:26
Q字节在正确的轨道上,但是不管“debugPrint”是否定义了"DEBUG“,它都会打印。
为什么不将助手更改为"appendNewLine“呢?这就是:
func print(object: Any) {
#if DEBUG
Swift.print(object, appendNewLine: true)
#endif或者把名字改得更清楚一点:
func printDuringDebug(object: Any) {
#if DEBUG
print(object, appendNewLine: true)
#endifhttps://stackoverflow.com/questions/32439387
复制相似问题