Swift Setup
Before you write your first Swift program, you need the right tools on your machine. The setup is straightforward and takes about 15–20 minutes on a Mac.
What You Need
- A Mac running macOS 13 (Ventura) or later
- Xcode — Apple's free development tool
- An Apple ID (free to create)
Installing Xcode
Step 1: Open the Mac App Store
Click the App Store icon in your Dock or search for it using Spotlight (Command + Space, then type "App Store").
Step 2: Search for Xcode
Type "Xcode" in the App Store search bar. Xcode is published by Apple and is completely free.
Step 3: Download and Install
Click "Get" and then "Install." Xcode is a large download (around 8–12 GB), so make sure you have a stable internet connection and enough disk space.
Step 4: Launch Xcode
Once installed, open Xcode from your Applications folder. The first launch installs additional components automatically.
Diagram: Xcode Workspace Layout
+------------------------------------------------+
| Toolbar: Run | Stop | Device Picker |
+------------+-------------------+---------------+
| | | |
| Navigator | Code Editor | Inspector |
| (files, | | (settings, |
| errors) | func greeting() | attributes) |
| | { print("Hi") } | |
+------------+-------------------+---------------+
| Debug Console / Output Area |
+------------------------------------------------+
Xcode has four main zones. The Navigator on the left shows your project files. The Code Editor in the center is where you write Swift. The Inspector on the right shows settings. The Debug Console at the bottom shows output when you run your code.
Running Your First Swift Playground
What Is a Playground?
A Swift Playground is an interactive file where you write code and see results instantly — no need to build and run a full app. It is perfect for learning.
Create a Playground
- Open Xcode.
- Click File → New → Playground.
- Choose Blank under iOS or macOS.
- Name it HelloSwift and save it to your Desktop.
Write and Run Code
Delete any existing code and type this:
print("Hello, Swift!")Press the blue play button at the bottom left or use Shift + Command + Return to run it. The Debug Console shows:
Hello, Swift!
Swift on Linux (Optional)
Swift runs on Ubuntu and other Linux distributions. This is useful for server-side Swift work.
Install Swift on Ubuntu
- Visit swift.org/download and download the Linux toolchain for your Ubuntu version.
- Extract the archive and add the
binfolder to your PATH. - Run
swift --versionin a terminal to confirm the installation.
Using Swift Online (No Installation)
You can try Swift instantly without any installation at swiftfiddle.com or repl.it. These browser-based editors are great for quick experiments and sharing code snippets.
Checking Your Swift Version
Open the Terminal app and run:
swift --versionYou see output similar to:
swift-driver version: 1.90 Apple Swift version 5.10
Keeping Xcode Updated
Apple releases Xcode updates alongside new iOS and macOS versions. Always keep Xcode up to date through the Mac App Store to access the latest Swift features and bug fixes.
Summary
Setting up Swift takes three steps: install Xcode from the Mac App Store, open a Playground, and write your first print statement. You are now ready to write real Swift code.
