Swift Get Started
Swift Get Started
Install the Swift toolchain and run your first “Hello, Swift!” program from the terminal or Xcode.
Install Swift
Swift can be installed on macOS, Windows, and Linux.
- macOS (Xcode): Install Xcode from the App Store. Xcode includes the Swift compiler, SDKs, and tools.
- macOS (Command line): Install the Swift toolchain, then run
swift --version. - Windows/Linux: Install the platform toolchain from swift.org/install and ensure
swiftis on your PATH.
Check install: Run swift --version in a terminal.
You should see the Swift version and target.
Hello World
Swift can be run from the terminal or Xcode.
Syntax: print("Hello, Swift!"); run with swift main.swift (or your toolchain's run command).
Example
print("Hello, Swift!")
mkdir hello-swift
cd hello-swift
printf "print(\"Hello, Swift!\")\n" > main.swift
swift main.swift # or: swift run main.swift (depending on toolchain)
Hello, Swift!
Example explained
- main.swift: A Swift file; the top-level
printexecutes when run. - print: Writes text to standard output. Strings use double quotes.
Swift in Xcode
Create a new iOS app project (App template) in Xcode, choose Swift as the language, and run on the simulator.
You can also use a Playground for quick experiments.