Search code examples
iosswiftxcodemacosswift-playground

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?


Solution

  • 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>