Swift Playgrounds

Create interactive learning experiences for the Swift Playgrounds app.

Overview

You create content for the Swift Playgrounds app by writing playground books. Like traditional books, playground books are made up of chapters and pages. Unlike traditional books, they include executable Swift code that displays the results live, right on the page.

The pages of a playground book can include features that you use to teach a lesson or to encourage code experimentation. The basic building blocks you use on a page are:

  • Prose that introduces the material on the page.

  • Blocks of Swift code that learners can edit and expand upon.

  • The always-on live that view you use to show visualizations of running the page's code.

The following screenshot of a page from Learn to Code 1 shows a lesson on the left and an interactive live view on the right.

Screenshot showing the "Issuing Commands" playground page from Learn to Code 1.

You can further enrich a playground book and tailor it to your audience by adding cutscenes, glossaries, hints, and assessments. When you're done writing a playground book, you can distribute it locally in a classroom or workshop environment, or publish it online as a subscription.

Topics

Playground Setup

Creating and Running a Playground Book

Build a playground book from a template, and run it in Swift Playgrounds.

Structuring Content for Swift Playgrounds

Add chapters, pages, and cutscenes to a book by creating new folders and property lists.

Annotations

Use annotations in Swift comments to add functionality to a page's source editor.

Writing Prose for a Playground Page

Add comment markers in your Swift code to mark text as prose.

Specifying Editable Regions in a Playground Page

Guide learning by marking code that learners can change or copy forward.

Hiding Code from a Playground Page

Use special Swift comments to hide code from display but continue to run it.

Customizing the Completions in the Shortcut Bar

Guide learners toward a solution by hiding some symbols and showing others.

Glossaries

Adding a Glossary to a Playground Book

Define terms in the glossary property list and reference them on playground pages.

Hints

Giving Hints to Help Learners Solve Problems

Add hints, spoilers, and solutions to a page to help teach the material.

Subscriptions

Creating a Subscription

Create a machine-readable summary of a set of playground books to make them available for others to download.

Publishing a Subscription

Make the playground books in a series available online for download and subscription.

Localizing a Subscription Feed

Provide multiple localizations of a subscription's content in a single feed.

See Also