【问题标题】:How can I print to console in Swift Playgrounds on iPad?如何在 iPad 上的 Swift Playgrounds 中打印到控制台?
【发布时间】:2019-03-28 12:32:47
【问题描述】:

我想在 Swift Playground 的“Sources”文件夹深处调试一个方法。

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

在 macOS Playground 中,print 输出显示在调试区域中,如this question 中所述。

然而,在 iPad 上,print 语句似乎被忽略了。即使在 Mac 上的 Console.app 中,我也找不到所需的输出。

如何在 iPad 上编写调试语句以及在哪里可以找到它们?

【问题讨论】:

    标签: swift-playground


    【解决方案1】:

    虽然我找不到修改 Empty/Blank Playground 以提供控制台输入/输出的方法。有一个“答案”模板,您可以将其用于简单的控制台交互。

    另一种方法是使用“交互”模板,此处提供:https://buildingrainbows.com/2018/03/13/print-to-the-console-in-swift-playgrounds-for-ipad/

    【讨论】:

      【解决方案2】:

      此功能已添加到 iPad 上的 Swift Playgrounds 3.4 版

      【讨论】:

        【解决方案3】:

        为了将调试消息从 iPad 写入控制台,必须使用 NSLog()

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

        NSLog() 的输出可以在 macOS 的 Console.app 中名为 ExecutionExtension 的进程下找到。 print 消息的输出仅显示为<private>,可以在随附的屏幕截图中看到。

        【讨论】:

          猜你喜欢
          • 2021-09-26
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-03-04
          • 2014-08-28
          • 1970-01-01
          • 2013-05-22
          相关资源
          最近更新 更多