l'L'l
l'L'l

Reputation: 47284

Swift Playgrounds and Playground Books

I recently tried opening/editing a .playgroundbook project in Xcode Version 8.3.2 (8E2002), and was somewhat surprised that it didn't open as a "liveView Playground" (I realize it's mostly a package of .swift files with manifests).

Maybe I'm totally missing the point here, or was the format never intended to be used this way?

Upvotes: 1

Views: 1174

Answers (2)

marc-medley
marc-medley

Reputation: 9852

Swift 5, Xcode 11, Catalina

Swift Playgrounds can now run on either iPad or macOS (10.15.3 or newer).

Related: Swift Playgrounds Release Notes

Caveat: However, the most-recently available "Swift Playgrounds Author Template for Xcode 11.1 (for Swift Playground 3.3)" does not build "as-is" with the current Xcode 11.4.1 release.

enter image description here


Xcode 8

Creating and Running a Playground Book indicates that…

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

The only recommended (supported?) workflow for a *.playgroundbook appears to be "edit in Xcode, run on iPad" with Starter.playgroundbook provided as a starting point.

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

Note that an iPad Playgrounds +New PlaygroundBlank creates a non-book *.playground that can be run both on iPad and in Xcode.

Pages can be added although *.playground is not a *.playgroundbook.

Note: iPad currently uses a newer version of contents.xcplayground than Xcode 9, so CREATE a blank *.playground and ADD new *.playground pages on the iPad to be seen in both iPad or Xcode.

contents.xcplayground

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

Upvotes: 2

HuaTham
HuaTham

Reputation: 7596

Apple recently (WWDC '18) releases a new template that allows you to create, debug, and produce a PlaygroundBook right on your Mac.

You can use 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.

I write about this more in details in this answer

Upvotes: 0

Related Questions