Introduction

Swift is Apple's language for building iOS, macOS, watchOS, and tvOS apps, first released in 2014 as a safer, faster replacement for Objective-C. It's statically typed and compiled, and its compiler is deliberately strict about the kinds of mistakes that used to crash apps at runtime.

Your first Swift program

A Swift file needs no boilerplate — no class wrapper, no main function required for a simple script. print() writes to standard output:

Swift main.swift
print("Hello, Swift!")
Output
Hello, Swift!

Where Swift code runs

The easiest way to try Swift without installing anything is an online playground, or Xcode's built-in Playgrounds feature if you're on a Mac — both give you a line-by-line editor that shows each expression's result immediately. For a real app, Xcode compiles your Swift code into a native binary using the same LLVM-based toolchain that also compiles C and C++.

Comments and semicolons

Swift main.swift
// this is a single-line comment
print("No semicolon needed")  // but one is allowed here too
Output
No semicolon needed
Note: unlike C, C++, C#, and Java, Swift doesn't require a semicolon at the end of a statement — the compiler uses line breaks to figure out where one statement ends. You can still add one if you want to fit two statements on one line, but it's a stylistic choice, not a requirement.