In This Tutorial
Welcome to the Ultimate Swift Language Series. In this first chapter, you'll set up everything you need to start writing Swift code. By the end, you'll have Xcode running and your first Swift program working in a playground.
No prior programming experience is required. If you've never written a line of code before, you're in the right place.
What Is Swift and Why Learn It?
Swift is Apple's programming language for building apps on every Apple platform — iPhone, iPad, Mac, Apple Watch, Apple TV, and Vision Pro. Apple introduced it in 2014 as a modern replacement for Objective-C, and it has since become one of the most popular programming languages in the world.
Here's why Swift is worth learning:
- It powers the App Store ecosystem — over 1.8 million apps are built with it
- It's beginner-friendly — clean syntax that reads almost like English
- It's safe by design — the compiler catches common mistakes before your code runs
- It's fast — performance comparable to C++ for most tasks
- It's in demand — iOS developers are consistently among the highest-paid in tech
- It goes beyond mobile — server-side Swift (Vapor), command-line tools, and even embedded systems
Whether you want to build the next great iPhone app, a macOS productivity tool, or an Apple Watch companion — it all starts with Swift.
What You'll Need
Before writing any code, let's make sure your setup is ready. You need two things:
1. A Mac running macOS Sequoia 15 or later
Swift development requires a Mac. If you're on an older macOS version, open System Settings → General → Software Update and install the latest version. Always keep security patches current — Apple ties Xcode versions to macOS versions, so staying updated avoids compatibility headaches.
Any Mac from 2018 or later will work fine. Apple Silicon Macs (M1 and newer) compile Swift significantly faster than Intel models, but either works. Xcode needs about 35 GB of disk space, so make sure you have room.
2. Xcode 16.2 or later
Xcode is Apple's free development environment. It includes everything you need: a code editor, compiler, debugger, simulator, and Interface Builder. We need version 16.2 at minimum because it ships with Swift 6 — the version this entire series is based on.
Swift 6 introduced major language changes including strict concurrency checking and typed throws. All code examples in this series use Swift 6 features, so running an older version will cause compiler errors.
Setup checklist
- macOS Sequoia 15+ installed and up to date
- Xcode 16.2+ downloaded from the Mac App Store
- Opened Xcode once and installed command-line tools when prompted
- At least 35 GB free disk space
Installing Xcode
Open the App Store on your Mac and search for "Xcode." Tap Get, then Install. The download is large (around 13 GB compressed), so give it some time on slower connections.
When you open Xcode for the first time, it will ask to install additional components (command-line tools and platform support). Click Install and wait — this can take 5-10 minutes. It only happens once.
Once installation finishes, launch Xcode from your Applications folder. You'll see the Welcome window with options to create a new project, clone a repository, or open an existing project. For now, we'll use something simpler: a playground.
Creating Your First Playground
A playground is a special Xcode file that lets you write and run Swift code instantly, without building a full app. Think of it as a scratch pad — you type code on the left, and results appear on the right in real time. It's the fastest way to learn Swift.
Here's how to create one:
- Open Xcode (if it's not already open)
- From the menu bar: File → New → Playground
- Choose Blank under the macOS or iOS tab (either works for learning Swift)
- Name it something like
SwiftBasicsand save it anywhere convenient
Xcode will create the playground and open it. You'll see a code editor on the left with some starter code, and a results sidebar on the right.
Writing Your First Swift Code
Your new playground should contain one line of code:
Let's break this down:
import Cocoa— this loads Apple's framework so you can use system features. On iOS playgrounds, this will sayimport UIKitinstead. Both are fine for learning Swift basics.var greeting = "Hello, playground"— this creates a variable namedgreetingand stores the text "Hello, playground" in it.
Now let's add our own code. Click at the end of the last line, press Return, and type:
Press Shift + Return or click the blue Play button at the bottom of the editor to run the playground. In the results sidebar (and the console at the bottom), you should see:
Congratulations — you just wrote and ran your first Swift program.
Let's unpack what we wrote:
// My first Swift code— a comment. The compiler ignores anything after//. Use comments to leave notes for yourself.print()— a built-in function that outputs text to the consolelet— declares a constant (a value that can't change)var— declares a variable (a value that can change)\(myName)— string interpolation, which inserts a value inside a string
Change "Swift Developer" to your actual name and run the playground again. Experiment! Change the year, add more print() statements, see what happens. Playgrounds are designed for tinkering.
How Playgrounds Work
Playgrounds are different from normal Xcode projects in a few important ways:
- Instant feedback — code runs automatically (or when you press Play) and results appear in the sidebar
- Line-by-line results — hover over any line in the results sidebar to see what that specific line produced
- No app needed — you don't need to create a project, set up a simulator, or press Build. Just write and run.
- Great for learning — we'll use playgrounds for the first several chapters of this series before graduating to full Xcode projects
Playgrounds can sometimes be slow with large code blocks or when importing heavy frameworks. If the playground seems stuck, try pressing Editor → Run Playground from the menu bar, or restart Xcode. This is normal — playgrounds prioritize convenience over performance.
Next Steps
You now have a working Swift development environment and you've written your first code. Here's what we covered:
- What Swift is and why it's worth learning
- How to install Xcode and set up your Mac
- How to create and use a Swift playground
- The basics of
print(),let,var, comments, and string interpolation
In Chapter 2: Variables, Constants & Types, we'll dive deeper into how Swift handles data. You'll learn about integers, doubles, booleans, type inference, type safety, and why Swift makes you think about types more carefully than most languages.
Ship your apps faster
When you're ready to publish your Swift app to the App Store, Simple App Shipper handles metadata, screenshots, TestFlight, and submissions — all in one place.
Try Simple App Shipper