Skip to content
LumenaryAcademy

Lumenary CS · Programming languages

Swift

A safe, fast, expressive compiled language: from your first program to value types, protocols, Swift 6 concurrency and the apps built with it.

Swift is a general-purpose compiled language that Apple announced in 2014 and open-sourced in 2015. It is the main language for apps on iPhone, iPad, Mac, Apple Watch, Apple TV and Apple Vision Pro, and it also runs on Linux and Windows, where people use it for servers, command-line tools and, increasingly, embedded devices. Its designers name three goals, and the course keeps returning to them: code should be safe by default, run fast, and read clearly.

This course is for anyone who knows what a variable, a loop and a function are, for example from the Start level of Lumenary CS or equivalent experience. It goes from installing the toolchain and printing a first line to optionals, value and reference types, enums with associated values, protocols and generics, typed errors and tests, memory management with ARC, and the data-race safety of Swift 6, and it ends with a complete project. App frameworks such as SwiftUI and UIKit are described, but every program you run here uses only the standard library, so it works on any operating system.

To run the code, install the official toolchain from swift.org/install (Xcode on a Mac also includes it). There is no official online playground; Apple's free Swift Playgrounds app runs Swift on an iPad or Mac. Every complete program in these lessons was compiled with swiftc from Swift 6.4 on Linux and run, and its output is shown exactly as it printed.

AI-draftedAwaiting review by a computer scientist
  • Chloe · The Designer
    “Why is the language built this way?”
  • Margaret · The Profiler
    “What does it print, and what does it cost?”
  • Gideon · The Language Lawyer
    “What exactly does the language guarantee?”

Foundations · 4 lessons

The core language

Install the toolchain and learn the everyday language: constants and types, strings and collections, control flow and switch, and the optionals that keep missing values honest.

  1. 1First steps in SwiftWhere Swift came from, what it is for, how to install it, and your first compiled programs. 45 min
  2. 2Constants, variables and typeslet and var, numbers that never convert behind your back, Unicode-correct strings, tuples, and the three standard collections. 50 min
  3. 3Control flow and switchif and guard, loops over ranges and collections, and a switch statement that matches patterns and must cover every case. 50 min
  4. 4OptionalsA type for "maybe there is no value", and the safe ways to open it. 50 min

Practice · 3 lessons

Modelling with types

Write functions and closures, choose between structs, classes and enums, and build abstractions with protocols, extensions and generics.

  1. 5Functions and closuresArgument labels that make calls read like sentences, functions as values, and closures that capture the world around them. 55 min
  2. 6Structs, classes and enumsSwift's three kinds of named type, the difference between a value and a reference, and enums that carry data. 60 min
  3. 7Protocols, extensions and genericsDescribe what a type can do, add behaviour to types you did not write, and write code once for many types. 60 min

Professional · 3 lessons

Swift as professionals write it

Typed errors and tests, memory management with ARC, async/await and actors under Swift 6 data-race safety, how apps for Apple platforms are made, and a complete project.

  1. 8Errors and testingThrowing, catching and typed throws; when to trap instead; and proving your code works with Swift Testing. 60 min
  2. 9Memory and concurrencyWho keeps an object alive (ARC, weak and unowned), and who may touch it (async/await, actors, Sendable and Swift 6 data-race safety). 70 min
  3. 10Apps, platforms and a complete projectHow Swift apps for Apple devices are built, where else Swift runs, and a finished program that uses the whole course. 70 min

Further reading and resources

  • Swift.orgThe open-source project's home: downloads, blog, community and documentation.
  • The Swift Programming LanguageThe official book: a guided tour, the language guide and the formal language reference, which serves as Swift's specification.
  • Install SwiftOfficial toolchains for macOS, Linux and Windows, and the swiftly toolchain manager.
  • Swift documentationLinks to the standard library, Swift Package Manager, the API design guidelines and more.
  • Swift EvolutionEvery accepted and proposed change to the language, with its rationale.
  • Swift PlaygroundsApple's free app for writing and running Swift on iPad and Mac.