← Back to blog

What is a Swift Playground?

Swift Playgrounds let you write and run Swift code instantly, see results in real time, and experiment without creating a full project. Here's how to use them.

If you’re getting started with Swift, Playgrounds are your best friend. They let you write and run Swift code immediately, see results in real time and experiment without having to create a full project. In this post I’ll show you how to use them from scratch in Xcode.

What is a Swift Playground?

A Playground is an interactive Xcode environment where you can write Swift code and see the results of each line instantly, without compiling and running a full app. It’s ideal for:

  • Learning Swift and experimenting with new concepts
  • Quickly testing an idea or algorithm
  • Exploring Apple APIs without creating a project
  • Following tutorials like this post series

Requirements

  • Mac with macOS 13 or later
  • Xcode 15 or later — download it free from the Mac App Store

Creating a Playground from scratch

Open Xcode and go to File → New → Playground. Choose a template (Blank is fine to start), pick a platform (iOS or macOS), name it and save it.

Xcode will open the Playground with a basic Contents.swift file.

The Playground interface

The Playground has three main areas:

  • Code editor (left): where you write your Swift code
  • Results panel (right): shows the value of each expression in real time, inline next to the corresponding line
  • Console (bottom): shows output from print() and error messages

If you don’t see the console, enable it from the menu: View → Debug Area → Show Debug Area, or with the shortcut ⇧⌘Y.

Running the code

You have two ways to run:

  • Run all: click the ▶ button in the bottom left bar, or use ⇧⌘↩
  • Run up to a specific line: hover over the left margin next to the line number and click the ▶ button that appears — it runs all code up to that line

The Playground can also run automatically as you type. To enable it: Editor → Run Mode → Automatically Run.

Opening a downloaded Playground

The playgrounds you can download in this series come as a .zip file. To open them:

  1. Unzip the file — you’ll get a .playground package
  2. Double-click it and Xcode will open it automatically

If Xcode asks you to confirm opening an external file, accept with confidence.

Markdown in Playgrounds

Playgrounds support comments with Markdown formatting that render as styled text. This is how the playgrounds in this series are structured. To enable the rendered view:

  • Menu: Editor → Show Rendered Markup
  • Or right-click in the editor and select Show Rendered Markup
// Normal comment — doesn't render
// Just appears in the editor

//: ## This is a title (Markdown)
//: This is a paragraph with *emphasis* and **bold**.
//: It renders as formatted text when Rendered Markup is on.

let example = "the code still works the same"
print(example)

Tips for getting more out of Playgrounds

  • Experiment without fear: change the values in the examples and observe what happens. It’s the best way to learn.
  • Use print() generously: the side panel shows values but print() in the console is clearer for seeing program flow.
  • Divide code into sections: use //: --- or // MARK: - to separate concepts and navigate more easily.
  • Save your experiments: the Playground saves automatically but you can duplicate it before making heavy modifications.
  • Import frameworks: you can use import Foundation, import SwiftUI and other Apple frameworks directly in the Playground.

Limitations to keep in mind

  • Playgrounds are slower than a real project — don’t use them for performance testing
  • Some APIs require a simulator or device (like those related to camera, GPS, etc.)
  • For real projects with multiple files, create a normal Xcode project

Start now

All posts in the Modern Swift 2026 series include a downloadable Playground ready to run. Each one has the code organized into sections with explanatory comments. The best way to learn is to read the post while experimenting with the code in Xcode.

  • Basics 01 — Variables and Constants
  • Basics 02 — Basic Operators
  • Basics 03 — Control Flow
  • Basics 04 — Optionals
  • Basics 05 — Functions
  • Basics 06 — Classes and Structures