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 code, explore system APIs, and even create custom views. You can also add notes and guidance using rich comments, group related concepts into pages, then add navigation. In playgrounds, you can run code from the insertion point supporting an incremental development style. When you’ve perfected your code in the playground, simply move that code into your project.

Create a playground

  1. Choose File > New > Playground.

  2. In the sheet that appears, select the platform you want the playground to run on.

  3. Under Playground, select a template, then click Next.

    The templates are:

    • Blank: A generic playground.

    • Game: A playground based on SpriteKit.

    • Map: A playground that uses MapKit.

    • Single View: A playground with a single view.

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

Edit a playground

Note: The source editor in a playground has the same features as the source editor in the project editor.

Run a playground

You can run code automatically when you stop typing code or manually when you are ready. While the code executes, a progress indicator in the toolbar displays on the right, and when the code finishes, the results appear in the same location.

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