【问题标题】:Swift Playgrounds and Playground BooksSwift Playgrounds 和 Playground 书籍
【发布时间】:2017-05-23 17:37:11
【问题描述】:

我最近尝试在 Xcode 版本 8.3.2 (8E2002) 中打开/编辑 .playgroundbook project,但有点惊讶它没有以“liveView Playground”的形式打开(我意识到它是主要是带有清单的 .swift 文件包)。

也许我完全忽略了这一点,或者这种格式从未打算以这种方式使用?

【问题讨论】:

  • 我觉得没有关系,但是你用的是osx还是macOS?
  • afaik .playgroundbook 格式主要用于 iPad。因此,它不会在 Xcode 上显示为 liveView。

标签: ios swift xcode macos swift-playground


【解决方案1】:

Swift 5、Xcode 11、Catalina

Swift Playgrounds 现在可以在 iPad 或 macOS (10.15.3 or newer) 上运行。

相关:Swift Playgrounds Release Notes

警告:但是,最新可用的 "Swift Playgrounds Author Template for Xcode 11.1 (for Swift Playground 3.3)" 不会在当前 Xcode 11.4.1 版本中“按原样”构建。


Xcode 8

Creating and Running a Playground Book 表示……

您同时使用运行 Xcode 的 Mac 和 iPad 来创建 Playground Book。

*.playgroundbook 唯一推荐(支持?)的工作流程似乎是“在 Xcode 中编辑,在 iPad 上运行”,并以 Starter.playgroundbook 作为起点。

建议的工作流程是:

  1. 在 Xcode 中对本书的内容和结构进行有针对性的更改
  2. 使用 iCloud 或 AirDrop 将更新的图书传输到 Swift Playgrounds
  3. 打开更新的书并测试更改
  4. 记下所需的任何其他更改,然后返回第 1 步

请注意,iPad Playgrounds +New PlaygroundBlank 会创建一个非图书 *.playground 可以在 iPad 和 iPad 上运行Xcode。

虽然*.playground 不是*.playgroundbook,但可以添加页面。

注意:iPad 当前使用的 contents.xcplayground 版本比 Xcode 9 更新,因此请在 iPad 上创建一个空白 *.playground 并添加新的 *.playground 页面,以便在 iPad 或 Xcode 中看到。 em>

contents.xcplayground

<playground version='6.0' target-platform='ios'>
    <pages>
        <page name='Page One'/>
        <page name='Page Two'/>
    </pages>
</playground>

【讨论】:

  • 您实际上并不需要 iPad,因为现在可以直接在 Mac 上的 Playgrounds 应用程序中测试您的 .playgroundbook。只需双击它
【解决方案2】:

Apple 最近(WWDC '18)发布了一个新模板,允许您直接在 Mac 上创建、调试和制作 PlaygroundBook。

你可以使用Playgrounds Author Template:

Swift Playgrounds 作者模板是一个入门 Xcode 项目,可帮助您创建、调试和制作 Playground 书籍。使用该模板,您可以将实时视图的代码单步执行,就好像它是一个应用程序一样,这样您就可以更轻松地识别错误并开发高效的工作流程来开发 Playground 图书。

我在this answer 中写了更多详细信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 2019-05-22
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多