Guides and Sample Code


Playground Book Format Reference

On This Page

Publishing Subscriptions

You'll need to put your playgrounds online so learners can download the playground books that make up your subscription. Uploading files usually involves a web host, which is a service provider that specializes in making data available online. Almost any web host meets the requirements for putting a playground subscription online. However, the host must support TLS 1.3 encryption. You store a subscription’s playgrounds (zipped .playgroundbook files) as well as its feed (a JSON file) and supporting resources on the web host.

Be sure to note the URLs that your web host uses to store each file; you'll use these to fill in the parts of the feed format described in Subscription Feed Format with URLs customized to your specific web host and your playground subscription. These URLs should match up with the URLs in the feed JSON.

Some web hosts have a file upload facility that lets you drag and drop a hierarchy of directories and files from your local filesystem. When writing the JSON for a feed, it can be helpful to compare the structure of your feed’s files with the structure of the URLs in the feed.

Figure 19-1A directory structure corresponding to the JSON example shown in Creating Subscriptions. image: ../Art/SP_subscriptions_folder_structure_2x.png

Building a Landing Page for Your Playgrounds

If you have an existing personal, business, or school website, you can add a page to that site linking visitors to your Swift Playgrounds subscriptions.

To add a link to your feed, you'll need two pieces of information:

  1. The URL for your subscription's JSON feed. For example:

  2. The Swift Playgrounds universal link prefix:

Combine the two URLs to form a link on your site. The example below shows a HTML link surrounded by a descriptive sentence:

  1. Check out my
  2. <a href="">
  3. Swift Playgrounds subscription series
  4. </a>
  5. that whimsically highlights interesting facets of Swift!

Localizing a Feed

You can provide localizations of your subscription content by first linking to a supplemental JSON object that maps locale IDs to locale-specific feeds.



Locale ID

A link to the localized JSON feed file for the specified locale.

Figure 19-2Unlocalized feed URLs point directly to feeds, while localized feeds first point to a locales dictionary. image: ../Art/SP_subscription_localization_2x.png

For example, you can supply the following locale JSON to support a feed that’s localized to contain English and French versions of a subscription’s content:

  1. {
  2. "en": "en-feed.json",
  3. "fr": "fr-feed.json"
  4. }

Manually Adding a Subscription

If you want to distribute your playground in a classroom or workshop environment, you can instruct learners to enter the URL of your feed manually. In Swift Playgrounds, press the "Add Subscription" button and enter the URL for your feed. Manually-entered URLs must not include the Swift Playgrounds subscriptions universal link prefix. Instead, use the raw URL from your web host for the feed.