Course

Swift from the ground up

The language of Apple, and beyond

  • Beginner
  • 12 chapters
  • 197 min read

Learn Swift by running it: printing and top-level code, let and var with types, string interpolation, if and switch with ranges, loops, functions with labels and defaults, optionals, arrays and dictionaries with map and filter, tuples, enums with associated values, structs, protocols, closures, error handling, and a capstone report.

What You'll Learn

  • Write a program that runs from the first line and prints a line of text
  • Hold values in let and var, and know how whole numbers and decimals behave
  • Build text with a backslash, parentheses and the everyday string tools
  • Branch with if, else, switch and ranges
  • Repeat work with for-in, while and repeat
  • Write functions with argument labels, defaults and return values
  • Handle values that may be missing with optionals, if let and guard let
  • Keep lists and keyed tables, and fold them with map, filter, sort and reduce
  • Group values in tuples and model choices with enums and associated values
  • Model a thing with a struct, a computed property and a protocol
  • Pass a closure to a function, and throw and catch an error
  • Build a ranked report by filtering, sorting and summarising records

Prerequisites

  • No programming experience needed — this course starts at the first line
  • Any other language you know will make the early chapters quick

Vocabulary

The terms the chapters assume, in plain words.

array
An ordered list of values of one type, reached by position starting at zero.
block
A group of lines of code that run together, often inside curly brackets.
closure
A piece of code you can store in a value and pass to other code, remembered with the names around it.
compiler
The program that turns the code you write into something the machine can run, reporting mistakes before it does.
dictionary
A collection of key and value pairs, where each key appears once and finds its value.
enum
A type whose value is one of a fixed set of named cases, which may each carry extra data.
expression
A piece of code that produces a value, such as a sum or a call to a function.
function
A named piece of code that takes values and returns a result when called.
guard
A check that must pass before the code after it runs, leaving the scope early when it fails.
method
A function that belongs to a type and is called on a value of that type.
nil
The absence of a value, allowed only where a type says a value may be missing.
operator
A symbol such as plus or equals that combines values into a new one.
optional
A type that either holds a value or holds nothing, written with a question mark after the type.
optional chaining
Writing a question mark before something you reach into, so the result is nil when the value is missing.
property
A named value that belongs to a type or to one of its values.
protocol
A list of requirements that a type promises to meet, so code can work with any type that meets them.
scope
The region of code where a name can be used before it goes out of reach.
string interpolation
Putting a value inside text with a backslash and parentheses, so the value becomes part of the text.
struct
A type that groups related values and makes a copy whenever it is given another name or passed along.
subscript
A way to read or write an item in an array or dictionary by putting a key or position in square brackets.
type
What kind of value something is, such as a whole number or text, and what it can do.
unwrap
To get the value out of an optional after checking that something is there.

Course Content

  1. 01
    Your first Swift program

    What Swift is for, how a program is a list of steps, and how to print a line of text on the screen.

    Beginner · 12 min read

    Not started
  2. 02
    Values and types

    Holding numbers and text in named values, choosing between let and var, and how whole numbers and decimals behave.

    Beginner · 14 min read

    Not started
  3. 03
    Text and interpolation

    Building text with a backslash and parentheses, joining strings, and the everyday string tools worth knowing.

    Beginner · 14 min read

    Not started
  4. 04
    Decisions with if and switch

    Choosing a path with if and else, sorting many answers with switch, and matching ranges of numbers.

    Beginner · 15 min read

    Not started
  5. 05
    Loops and ranges

    Repeating work with for-in, counting with ranges, and looping while a condition still holds.

    Intermediate · 15 min read

    Not started
  6. 06
    Functions and their labels

    Naming a step, handing values in, returning a result, and the argument labels that make a call read like a sentence.

    Intermediate · 16 min read

    Not started
  7. 07
    Optionals

    The value that may be missing, the question mark that says so, and the safe ways to open, guard and replace a missing value.

    Intermediate · 17 min read

    Not started
  8. 08
    Arrays and dictionaries

    Lists that keep order, keyed lookups, and the four tools that work on a whole collection at once.

    Intermediate · 18 min read

    Not started
  9. 09
    Tuples and enums

    Grouping a few values without a name, and a fixed set of cases where each case can carry its own data.

    Advanced · 18 min read

    Not started
  10. 10
    Structs and protocols

    A struct that models a thing, properties it computes on demand, and a protocol that states what a type can do.

    Advanced · 19 min read

    Not started
  11. 11
    Closures and errors

    A block of code you can pass around, and how Swift reports a failure that a caller must deal with.

    Advanced · 19 min read

    Not started
  12. 12
    Capstone: a records report

    Modeling a record as a struct, keeping only the ones that qualify, sorting them, and printing a tidy report.

    Advanced · 20 min read

    Not started