Swift Tutorial · Swift Basics · Lesson 2 of 30
Swift Get Started
Install Swift with Xcode or the swift.org toolchain, create a package, and build and run it.
Install
- macOS: install Xcode from the App Store; it includes Swift, the iOS SDKs and simulators.
- Linux and Windows: install the toolchain from swift.org/install
(the
swiftlyinstaller manages versions).
swift --version
Swift Package Manager
mkdir Hello && cd Hello
swift package init --type executable # Package.swift and Sources/main.swift
swift run # build and run
swift build -c release # optimised build
swift test # run tests
Sources/main.swift starts as:
print("Hello from my first Swift package!")
Output
Hello from my first Swift package!
Run this on your computer — see “Get Started” for setup.
iOS and macOS apps are created in Xcode (File > New > Project), which uses the same Swift language with Apple's frameworks such as SwiftUI.
Test yourself
Which command builds and runs a Swift package?
swiftc startswift runxcode runswift package go
Show answer
Answer: swift run