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.
Swift Basics
- Swift Introduction — What Swift is, where it's used (iOS, macOS, servers, Linux), and what a Swift program looks like.
- Swift Get Started — Install Swift with Xcode or the swift.org toolchain, create a package, and build and run it.
- Swift Syntax and Output — Statements, comments, print, and string interpolation for formatted output.
- Swift Variables and Constants: let and var — Declare constants with let and variables with var, and let type inference choose the type.
- Swift Data Types — Int, Double, Bool, Character and String, tuples, and type aliases.
- Swift Strings — Work with strings and characters: common methods, multiline strings, Unicode-correct counting and substrings.
- Swift if, guard and switch — Branch with if and switch (both usable as expressions), and exit early with guard.
- Swift Loops and Ranges — Loop with for-in over ranges and collections, stride, while and repeat-while, and labelled statements.
- Swift Functions — Declare functions with argument labels, default values, variadic and inout parameters, and multiple returns.
- Swift Optionals — Represent missing values with optionals and unwrap them safely with if let, guard let, ?? and optional chaining.
- 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
- Swift Arrays, Dictionaries and Sets — Store values in arrays, dictionaries and sets, and know why Swift collections are value types.
- Swift Structs — Define value types with stored and computed properties, methods, mutating methods and memberwise initializers.
- Swift Classes and Reference Types — Classes, initializers, inheritance, reference semantics, and when to choose a class over a struct.
- Swift Enums — Enums with raw values, associated values, methods, CaseIterable, and exhaustive switch.
- Swift Protocols — Define shared behaviour with protocols, give it default implementations in extensions, and use some and any.
- Swift Extensions — Add methods, computed properties, initializers and protocol conformances to existing types.
Closures, Generics and Errors
- Swift Closures — Closure syntax and its shorthand forms, trailing closures, capturing values, and escaping closures.
- Swift map, filter, reduce and More — Transform collections with map, filter, reduce, compactMap, sorted, grouping and key paths.
- Swift Generics — Write reusable functions and types with generic parameters, constraints and where clauses.
- Swift Error Handling — Throw, propagate and catch errors with throws, try, do-catch, typed throws, try? and Result.
Swift Concurrency
- Swift async and await — Write asynchronous code with async functions, await, async let and Task.
- Swift Task Groups and Cancellation — Run a dynamic number of child tasks with task groups, collect their results, and handle cancellation.
- 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
- Swift Memory Management: ARC and weak References — How automatic reference counting works, retain cycles, and breaking them with weak and unowned.
- Swift Property Wrappers — Reuse property logic with property wrappers, the feature behind SwiftUI's @State and @Binding.
- Swift Codable and JSON — Encode and decode JSON with Codable, custom keys, snake_case conversion and dates.
Swift Projects
- Swift Testing — Write tests with the Swift Testing framework: @Test, #expect, #require and parameterized tests.
- Swift Packages, SwiftUI and Server-Side Swift — How real Swift projects are organised: Swift packages, SwiftUI apps, and Swift on the server.
- Swift Next Steps — Where to go after this tutorial: the Swift book, building iOS apps with SwiftUI, server-side Swift and related courses.