Use and create playgrounds in Swift Playgrounds on Mac
In addition to working with app projects, you can use and create playgrounds in Swift Playgrounds. To view sample playgrounds, go to the More Playgrounds screen—the sample playgrounds are in the Books section at the bottom.
In the Swift Playgrounds app on your Mac, click a playground in the Books section at the bottom of the More Playgrounds screen to view a description.
If you’re in the My Playgrounds window, click See All near the bottom right to go to the More Playgrounds screen.
If you’re working in an app project or playground, choose Window > My Playgrounds, then click See All near the bottom right.
Click to return to the More Playgrounds screen, then click Get to download the playground.
After it’s downloaded, double-click the playground to open it.
If the playground begins with an Introduction, click to page through the Introduction, then click Start Coding at the end of the introduction.
The playgrounds have sample code you can run. To step through the code and see it become highlighted as it runs, click , then choose Step Through My Code (or use the Run My Code button in the Touch Bar).
To create a new playground, go to the My Playgrounds window (choose Window > My Playgrounds or click at the top left of the More Playgrounds screen), then click the Playground button near the bottom left. The playground this creates (called My Playground) has no code or images.
When you’re ready to add your own code, see Enter code in a playground. You can apply what you learned in the Learn to Code playgrounds and other playgrounds where you tried running code.
You can also explore the code in any preexisting shared Swift files that come with the template. See Work with shared files.