ios - 你如何调试 Swift PlaygroundBook?

标签 ios swift xcode debugging swift-playground

当我探索 Playground Book 示例代码时,例如 this one ,我发现让代码运行起来非常乏味,因为 Playground Book 对代码运行的位置有限制:只能在 iPad 的 Swift Playground 上运行。

无法在 iOS 的 Swift Playground 中调试“源”/辅助代码,因为所有源文件都以不可编辑的纯文本显示。您必须在 Xcode 中打开源文件才能编辑它们,但是您无法编译或运行它们!

这对于上面的示例代码来说尤其繁琐,它使用了PlaygroundValue,一个需要Playground Book格式的持久性API,所以我仍然无法通过将所有源代码分离成代码来运行代码在 Mac 上运行的单独的 Playground 文件。

由于上面的示例代码已经过时,我发现要正确调试它并让代码运行几乎是不可能的。你必须:

  • 在 iPad 上部署代码。运行本书。
  • 在 iPad 上看到许多错误消息。
  • 返回到 Mac 上的 Xcode 并手动调试它们。
  • 再次在 iPad 上部署代码运行。重复该过程。
  • 即使在所有错误都已解决之后,您仍然会面临神秘的“问题运行 Playground ”,而无需任何进一步的具体解释。

enter image description here enter image description here

使用 Playground Book 高效调试和部署代码的工作流程是什么? Current workflow对我来说似乎不切实际我认为必须有更好的方法,但我对 Playground Book 不够熟悉并且我的在线研究没有产生任何合理的解决方法。

最佳答案

根据我发送给 Apple 的错误报告/建议,我得到了以下回复:

We’ve actually built tools to help debug the auxilliary sources and we did a presentation at WWDC 2018 that demonstrates it. Please view the presentation and get access to the tools here: https://developer.apple.com/videos/play/wwdc2018/413/

经过进一步研究,我发现他们最近发布了一个 Playgrounds Author Template :

The Swift Playgrounds Author Template is a starter Xcode project that will help you create, debug, and produce a Playground book. Using the template you can step through the code for your live view as if it were an app so that you can identify bugs more easily and develop an efficient workflow for developing your Playground books.

此模板需要 Swift 4.1 才能运行,包括三个不同的目标:

  • 游戏本
  • Book_Sources
  • LiveViewTestApp

enter image description here

您可以使用 LiveViewTestApp 在装有 Xcode 的 Mac 上对您的 Playground Book 进行全面调试。

关于ios - 你如何调试 Swift PlaygroundBook?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51247539/

相关文章:

swift - 如何在 Vapor 3 中将字典转换为 JSON?

php - 我无法在 php 文件中从应用程序接收注册信息,无法将该信息插入 MSQL 数据库

ios - ARKIT 根据物理对象改变节点位置

ios - FIRMessaging 代理错误

objective-c - iOS 在重新加载数据后将选定的背景设置为表格行?

ios - Xcode:应用程序无错误退出

iphone - 如何在不使用 USB 线的情况下在 iPad/iPhone 上安装应用程序?

ios - 我们如何在 iOS Appcelerator 中获取设备 token

ios - Swift 如何使用动画淡入新图像然后淡入旧图像

swift - 检查新整数与前一个整数的问题