Free tutorial · 30 lessons

Swift Tutorial

Learn Swift step by step: constants and variables, types and strings, control flow, functions, optionals, collections, structs and classes, enums, protocols and extensions, closures, generics, error handling, async/await, task groups, actors and data-race safety, ARC, property wrappers, Codable and Swift Testing. Every example is compiled with Swift 6.4 and run.

Start learning →

Swift Basics

  1. Swift Introduction — What Swift is, where it's used (iOS, macOS, servers, Linux), and what a Swift program looks like.
  2. Swift Get Started — Install Swift with Xcode or the swift.org toolchain, create a package, and build and run it.
  3. Swift Syntax and Output — Statements, comments, print, and string interpolation for formatted output.
  4. Swift Variables and Constants: let and var — Declare constants with let and variables with var, and let type inference choose the type.
  5. Swift Data Types — Int, Double, Bool, Character and String, tuples, and type aliases.
  6. Swift Strings — Work with strings and characters: common methods, multiline strings, Unicode-correct counting and substrings.
  7. Swift if, guard and switch — Branch with if and switch (both usable as expressions), and exit early with guard.
  8. Swift Loops and Ranges — Loop with for-in over ranges and collections, stride, while and repeat-while, and labelled statements.
  9. Swift Functions — Declare functions with argument labels, default values, variadic and inout parameters, and multiple returns.
  10. Swift Optionals — Represent missing values with optionals and unwrap them safely with if let, guard let, ?? and optional chaining.
  11. Swift History & Versions — How Swift went from a secret Apple project to an open-source language for Apple platforms, servers, Linux and Android, the road to ABI stability and data-race safety, and which version to use today.

Collections and Types

  1. Swift Arrays, Dictionaries and Sets — Store values in arrays, dictionaries and sets, and know why Swift collections are value types.
  2. Swift Structs — Define value types with stored and computed properties, methods, mutating methods and memberwise initializers.
  3. Swift Classes and Reference Types — Classes, initializers, inheritance, reference semantics, and when to choose a class over a struct.
  4. Swift Enums — Enums with raw values, associated values, methods, CaseIterable, and exhaustive switch.
  5. Swift Protocols — Define shared behaviour with protocols, give it default implementations in extensions, and use some and any.
  6. Swift Extensions — Add methods, computed properties, initializers and protocol conformances to existing types.

Closures, Generics and Errors

  1. Swift Closures — Closure syntax and its shorthand forms, trailing closures, capturing values, and escaping closures.
  2. Swift map, filter, reduce and More — Transform collections with map, filter, reduce, compactMap, sorted, grouping and key paths.
  3. Swift Generics — Write reusable functions and types with generic parameters, constraints and where clauses.
  4. Swift Error Handling — Throw, propagate and catch errors with throws, try, do-catch, typed throws, try? and Result.

Swift Concurrency

  1. Swift async and await — Write asynchronous code with async functions, await, async let and Task.
  2. Swift Task Groups and Cancellation — Run a dynamic number of child tasks with task groups, collect their results, and handle cancellation.
  3. Swift Actors, Sendable and Data-Race Safety — Protect mutable state with actors, understand Sendable, and how the Swift 6 language mode prevents data races.

Advanced Swift

  1. Swift Memory Management: ARC and weak References — How automatic reference counting works, retain cycles, and breaking them with weak and unowned.
  2. Swift Property Wrappers — Reuse property logic with property wrappers, the feature behind SwiftUI's @State and @Binding.
  3. Swift Codable and JSON — Encode and decode JSON with Codable, custom keys, snake_case conversion and dates.

Swift Projects

  1. Swift Testing — Write tests with the Swift Testing framework: @Test, #expect, #require and parameterized tests.
  2. Swift Packages, SwiftUI and Server-Side Swift — How real Swift projects are organised: Swift packages, SwiftUI apps, and Swift on the server.
  3. Swift Next Steps — Where to go after this tutorial: the Swift book, building iOS apps with SwiftUI, server-side Swift and related courses.

Was this page helpful?