Create Swift Playgrounds content for iPad and Mac

Description: Learn how to create Swift Playgrounds books that work fluidly across both Mac and iPad and help people of all ages explore the fun of coding in Swift. We’ll walk you through how to customize content for each platform while considering platform settings, and help you take advantage of them in your playgrounds while still providing a smooth cross-platform experience. For more on Swift Playgrounds, check out "Build a SwiftUI view in Swift Playgrounds", and try your hand with "Swan’s Quest".

  • Swift Playgrounds on Mac is the same app as in iPadOs thanks to Catalyst.

Code completion in macOS vs. iPadOS


Customizing content for each platform

Device availability

In the playground book document format we have two new optional keys:

  • In Manifest.plist:
  • In feed.json:
    • supportedDevices: same as above
    • requiredCapabilites: same as above

By setting any of these, the book will only show up on devices that met those requirements.

RequiredCapabilites is more flexible than SupportedDevices as we can specify exactly which capabilities our book required.

Code availability

Instead or requiring a specific capability such as arkit, you can also use the #if targetEnvironment() compilation conditional block to customize content for each platform, for example:

#if !targetEnvironment(macCatalyst)
// Code to exclude from Mac.

Respecting platform settings

When creating something for all platforms, instead of using liveViewSafeAreaGuide, use safeAreaLayoutGuide, because there are different layouts/overlays in iPadOS and macOS.

Missing anything? Corrections? Contributions are welcome 😃


Written by

Federico Zanetello

Federico Zanetello

iOS Engineer with strong passion for Swift, minimalism, and design. When he’s not busy automating things, he can be found writing at FIVE STARS and/or playing with the latest shiny toys.