How can I print to console in Swift Playgrounds on iPad?

亡梦爱人 提交于 2019-12-20 06:19:23

问题


I would like to debug a method deep inside my "Sources" folder within a Swift Playground.

public func wannaDebugThis() {
    let x = 42
    let text = "Debug message with useful information: x = \(x)"
    print(text)
}

Within a macOS playground, the print output is shown in the debug area, as described in this question.

On iPad however, the print statement seems to be ignored. Even within Console.app on mac, I cannot find the desired output.

How do I write debug statements on iPad and where do I find them?


回答1:


While I couldn‘t find a way to modify an Empty/Blank Playground to provide console in-/output. There is the „Answers“ template, that you can use for simple console interactions.

Another way is to use the „Interactions“ template, provided here: https://buildingrainbows.com/2018/03/13/print-to-the-console-in-swift-playgrounds-for-ipad/




回答2:


In order to write debug messages from the iPad to the console, NSLog() has to be used.

public func wannaDebugThis() {
    let x = 42
    let text = "Debug message with useful information: x = \(x)"
    NSLog(text)
}

The output of NSLog() can be found under the process named ExecutionExtension in Console.app on macOS. The output of print messages is only shown as <private>, which can be seen on attached screenshot.



来源:https://stackoverflow.com/questions/55397751/how-can-i-print-to-console-in-swift-playgrounds-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!