An Introduction to Xcode 12 Playgrounds

Get started with a simple Xcode playground, and see how Playgrounds provide the ideal environment to learn Swift programming.

What is a Playground?

A playground is an interactive environment where Swift code can be entered and executed with the results appearing in real-time. This makes an ideal environment in which to learn the syntax of Swift and the visual aspects of app development without the need to work continuously through the edit/compile/run/debug cycle that would ordinarily accompany a standard Xcode project. With support for rich text comments, playgrounds are also a good way to document code for future reference or as a training tool.

Creating a new Playground

To create a new Playground, start Xcode and select the “File -> New -> Playground…” menu option. Choose the iOS option on the resulting panel, and select the Blank template.

The Blank template is useful for trying out Swift coding. The Single View template, on the other hand, provides a view controller environment for trying out code that requires a user interface layout. The game and map templates provide preconfigured playgrounds that allow you to experiment with the iOS MapKit and SpriteKit frameworks, respectively.

On the next screen, name the playground LearnSwift, and choose a suitable file system location to save the playground before clicking on the Create button.

Once the playground has been created, the following screen will appear ready for Swift code to be entered:

Get hands-on with 1400+ tech skills courses.