Playground Book Package
With the playground book package format, you can create a document that includes features such as playground pages, live views containing iOS views, and animated cutscenes. Figure 1-1 shows a screenshot from Learn to Code 1.
Content Hierarchy
A playground book is a package—a type of document with a file and folder structure. The parts of a book package form a nested hierarchy of folders. At the top is the book, then the chapters, and finally the individual pages and their content. The books, chapters, and pages include manifest information and optional items shared between the book, chapter, or page. Figure 1-2 shows the general hierarchy of files and folders for the playground book package format.
The package format uses a combination of folder name extensions, specially named folders, and specially named files. Manifest files for a book, and for each chapter and page, contain configuration information such as the order of chapters or the name of a page.
Folder Name Extensions
The book package, chapters, and pages use folder name extensions to indicate their type. Table 1-1 describes the folder name extensions and lists their locations in the hierarchy.
Extension |
Level |
Description |
|---|---|---|
|
Book |
The top-level folder for the playground book |
|
Chapter |
A chapter in the book |
|
Page |
An individual page containing a playground and an optional always-on live view |
|
Page |
An individual page containing a cutscene |
Folders in the Package Structure
The package structure consists of specially named folders with no folder name extensions. These folders contain the book, a chapter in the book, and the pages in a chapter. Table 1-2 describes the folders in the package structure and lists the containing folder for each.
Folder name |
Containing folder |
Description |
|---|---|---|
|
The top-level |
Contains all the other files and folders for the playground book |
|
|
Contains all the chapter folders for the book |
|
|
Contains all the page folders for the chapter |
Shared Folders
Shared code and resources are stored in specially named folders with no folder name extensions. The contents of the folders are shared by the level in the hierarchy at which they are defined and all levels below that. For example, code in the Sources folder at the book level is available to all chapters and pages. An image in a Resources folder at a chapter level is available to all pages in that chapter but not to any other chapter.
Table 1-3 describes the shared-element folder names and lists their containing folders.
Folder name |
Containing folders |
Description |
|---|---|---|
|
|
A folder containing shared resources such as images, sounds, and text files. |
|
|
A folder containing shared Swift code. |
Specially Named Files
Configuration information, playground contents, and the source code for always-on live views are in specially named files.
Table 1-4 describes the specially named files and lists their containing folders.
File name |
Containing folders |
Description |
|---|---|---|
|
|
A property list that defines the attributes for a book, chapter, or page. |
|
|
A required file with the initial contents of the playground page. For more information on formatting text for the rendered playground page, see Markup Formatting Reference. |
|
|
An optional file used to specify an always-on live view. The code in this file is executed when the page is opened. |
Creating Playground Books
You need to use both a Mac running Xcode and an iPad to create a playground book. The first step in development is creating a skeleton structure for the book. A simple approach is to start with an existing playground book, which you can get by downloading Starter.playgroundbook from the Apple developer website.
Any changes to a book, such as adding a new page, require modifying content files, manifest files, and the folder structure. Changes made to a book in Swift Playgrounds, such as entering code into an editable text field, do not change the underlying pages. The suggested workflow is:
Make targeted changes to the book’s content and structure in Xcode.
Transfer the updated book into Swift Playgrounds using iCloud or AirDrop.
Open the updated book and test the changes.
Note any additional changes that are needed, and return to step 1.
Copyright © 2016 Apple Inc. All rights reserved. Terms of Use | Privacy Policy | Updated: 2016-09-13
