Swift 游乐场和游乐场书籍

Swift Playgrounds and Playground Books

我最近尝试了 opening/editing .playgroundbook project in Xcode Version 8.3.2 (8E2002), and was somewhat surprised that it didn't open as a "liveView Playground”(我意识到它主要是一个带有清单 的 .swift 文件包)。

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

Swift5,Xcode11,卡特琳娜

Swift Playgrounds can now run on either iPad or 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 版本构建 "as-is"。


Xcode 8

Creating and Running a Playground Book表示……

You use both a Mac running Xcode and an iPad to create a playground book.

*.playgroundbook 唯一推荐(支持?)的工作流程似乎是 "edit in Xcode, run on iPad",并以 Starter.playgroundbook 为起点。

The suggested workflow is:

  1. Make targeted changes to the book’s content and structure in Xcode
  2. Transfer the updated book into Swift Playgrounds using iCloud or AirDrop
  3. Open the updated book and test the changes
  4. Note any additional changes that are needed, and return to step 1

注意 iPad Playgrounds +New PlaygroundBlank 创建了一个非书籍 *.playground 在 iPad 和 Xcode 中都可以是 运行。

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

注意:iPad 目前使用比 Xcode 9 更新的 contents.xcplayground 版本,所以创建一个空白 *.playground 并添加新的 [= iPad 上的 15=] 页在 iPad 或 Xcode 中都可以看到。

contents.xcplayground

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

A​​pple 最近 (WWDC '18) 发布了一个新模板,允许您直接在 Mac.

上创建、调试和制作 PlaygroundBook

您可以使用 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.

我在

中写了更多细节