Swift Get Started

Get set up with the tools you need to write and run your first Swift program.

Tools You Need

To write Swift code on a Mac, Apple provides Xcode, a free integrated development environment (IDE) that includes a code editor, compiler, debugger, and simulators for testing apps. For a lighter-weight, beginner-friendly experience, Apple also offers Swift Playgrounds, available on both Mac and iPad.

If you're on Windows or Linux, or simply want to experiment without installing anything, you can use an online Swift compiler or the interactive examples throughout this tutorial to try code instantly.

Installing Xcode

  • Open the Mac App Store and search for "Xcode"
  • Click Get / Install and wait for the download (it can be several gigabytes)
  • Launch Xcode and accept the license agreement
  • Choose File > New > Project to start a new app
  • Select a template such as "App" under the iOS tab

Writing Your First Program

Every Swift program needs an entry point where execution begins. In a simple script or Playground file, Swift runs code from top to bottom automatically — there's no need for a special main function like in C or Java.

Hello, Swift!

print("Hello, Swift!")

A Slightly Bigger Example

let myName = "Ganesh"
let greeting = "Welcome to Swift, \(myName)!"
print(greeting)
print("Let's start coding.")

Running Code in a Playground

// Playgrounds show results live in the sidebar
for i in 1...3 {
    print("Line number \(i)")
}
ToolBest For
XcodeFull app development with UI, debugging, simulators
Swift PlaygroundsLearning and quick experiments on Mac or iPad
Online compilerTrying snippets without any installation
Note: Xcode is only available on macOS. If you're using Windows or Linux, install the Swift toolchain from swift.org or use an online playground instead.
Note: Swift Playgrounds is a great starting point for beginners because it shows results instantly next to your code, without needing to build a full app.

Exercise: Swift Get Started

What is the conventional first line of code to print text in Swift?