Hello World in Xcode Playground: The First Step Towards Swift Programming

Xcode Playground

Xcode Playground is a powerful tool provided by Apple's integrated development environment (IDE), Xcode, to experiment, learn, and develop Swift code interactively. It offers a sandboxed environment where you can write and execute Swift code snippets in real time. One of the most iconic and traditional programs to start with in any programming language is the "Hello World" program. In this article, we will guide you through the process of creating your first program, the "Hello World" program, in Xcode Playground.

Setting up Xcode Playground

Before we dive into coding, let's ensure that you have Xcode installed on your Mac. Xcode is available for free on the Mac App Store. Once you have Xcode installed, follow these steps to create a new Xcode Playground:

  1. Launch Xcode on your Mac.
  2. In the welcome window, click on "Create a new Xcode playground," or go to "File" > "New" > "Playground" in the menu bar.
  3. Choose a location to save your playground and give it a name.
  4. Select "Blank" as the template for your playground.
  5. Click "Next" and choose the platform you want your playground to run on (iOS, macOS, or tvOS).
  6. Click "Create" to finish creating your Xcode Playground.

Writing the "Hello World" Program

Now that we have our Xcode Playground set up, it's time to write our "Hello World" program. Follow these steps:

  1. In the Xcode Playground editor, delete any existing code if present.
  2. Type the following code snippet:
                    import UIKit
                    var str = "Hello, World!"
  3. After typing the code, you should see the output "Hello, World!" in the console area on the right-hand side of the Xcode Playground window.

Running the "Hello World" Program

To run the "Hello World" program in Xcode Playground, follow these steps:

  1. Make sure the Xcode Playground window is active.
  2. Click on the "▶️" button in the bottom-left corner of the Xcode Playground editor, or use the shortcut "Command + Option + Enter" on your keyboard.
  3. Observe the output "Hello, World!" in the console area.


You have successfully written and executed your first program, the "Hello World" program, in Xcode Playground. This small but significant step marks the beginning of your journey into the world of Swift programming. From here, you can continue to explore the language and gradually build more complex applications.


In this article, we learned how to set up Xcode Playground and write the classic "Hello World" program in Swift. We also covered the process of running the program and saw the output in the Xcode Playground console. Now that you have taken this first step, you are ready to embark on a thrilling journey into Swift programming. Happy coding!

Previous Post Next Post