SwiftQuest

Guide

Learn Swift online, from your first line

Swift is the language behind Apple's apps, and one of the friendlier first languages there is. Here is what it is, what to learn first, and how to learn it by writing it.

What Swift is

Apple introduced Swift in 2014 and made it open source a year later. It is the main language for apps on the iPhone, iPad, Mac, Apple Watch and Apple TV, and it also runs on Linux and Windows, where people use it for servers and command-line tools. It is fast, it is strict about types, and its compiler explains a lot of mistakes before your program ever runs — which is exactly what you want while you are learning.

A whole Swift program can be two lines:

let name = "Sable"
print("Hello from Swift Camp. My name is \(name).")
// Hello from Swift Camp. My name is Sable.

And the very next thing worth knowing is that Swift works out the type of every value and holds you to it. Two whole numbers divide into a whole number:

print(7 / 2)     // 3 — both are Int, so the answer is an Int
print(7.0 / 2)   // 3.5 — a Double, so the answer is a Double

What to learn first

Swift is easiest in an order where each idea uses the ones before it. This is the order SwiftQuest's fifteen islands follow:

  1. Values, types and functions — and reading what the compiler tells you.
  2. Conditions, loops and optionals — deciding, repeating, and a value that might be missing.
  3. Arrays, sets and dictionaries — holding more than one thing.
  4. Structs — your own types, and what happens when you copy one.
  5. Enums with associated values — describing a situation so the impossible versions cannot be written.
  6. Classes — values that are shared rather than copied (structs vs classes).
  7. Protocols and generics — saying what a type can do without saying what it is.
  8. Closures — functions you hand to something else.
  9. Errors — throws, try and Result, for the things that go wrong.
  10. Memory — how Swift frees what nothing holds, and the cycles that stop it.
  11. Foundation, JSON and files — data that arrives from somewhere else.
  12. Regex — reading text written for people.
  13. Extensions, property wrappers and macros — removing repetition.
  14. Async, await and actors — waiting without blocking, and sharing safely.
  15. A whole program from a brief, with tests that say when it is done.

How to learn it: write it, run it, see what it did

Reading about Swift teaches you to recognise it. Writing it is what teaches you to use it. A SwiftQuest quest takes 30 to 50 minutes and goes like this:

  • Read a little, then run it. Each idea comes with a worked example you run and change, with a short checklist of things to try.
  • Predict, write, repair. Encounters ask you to predict what code prints, write a program from a brief, or fix one that will not build.
  • See what happened. Swift's own messages, explained in plain words, and replays that step through what your program actually did.

There are 40 quests, 148 encounters and 57 worked examples in all. You need no Mac and no Xcode: your code runs on SwiftQuest's servers, so any modern browser will do (more on learning Swift without a Mac).

What is free

The first two islands — The Swift Camp and Control Flow Keep — are free: five quests, about three to four hours for a beginner, with the Practice Lab for what they teach. Pro opens the other thirteen, by the month or once for good.

Learn it by writing it

SwiftQuest is a Swift course in fifteen islands. Every quest has you write real Swift and run it on a real compiler, in your browser, with nothing to install. It opens soon, and the first two islands are free.