gpt4 book ai didi

Swift 2 print(),如何隐藏?

转载 作者:搜寻专家 更新时间:2023-10-31 21:51:51 25 4
gpt4 key购买 nike

在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com