Create, edit, and execute playgrounds

Use playgrounds to learn and explore Swift, prototype parts of your app, and create learning environments for others. The interactive Swift environment lets you experiment with algorithms, explore system APIs, and even create custom views.

Share your learning with others by adding notes and guidance using rich comments. Create an explorable learning environment by grouping related concepts into pages and adding navigation.

Create a playground

  1. Choose File > New Playground.

  2. In the sheet, select the platform for the playground.

    Choose the platform you want the playground to run on.

  3. Under Playground, select a template for the playground, then click Next.

    The template will import the platform-specific framework into the playground. For example, if you choose iOS, UIKit is imported.

  4. In the sheet, enter the name of the file, select a location, then click Create.

Edit a playground

Execute a playground

Run the playground automatically each time code is added or changed, or run it manually.

While the playground code is being executed, you see a progress indicator in the toolbar, as shown below.

See alsoAdd, edit, and view rich commentsView detailed results of an executed statementAdd a color, file, or image literal