1. Meet Swift and the Swift toolchain
BeginnerUnderstand where Swift runs, how source code is compiled, and how to create and execute a small program.
What Swift is used for
Swift is a general-purpose programming language designed for safety, performance, and clear syntax.
Your first Swift program
A Swift program can start with executable statements at the top level or use an explicit main entry point.
Swift tools and the build workflow
The Swift compiler and Swift Package Manager support building and organizing Swift code.
Module checkpoint: Create a small Swift program that prints your name, a learning goal, and the result of a simple calculation. Run it and resolve any compiler errors or warnings.
2. Constants, variables, and types
BeginnerStore information using constants and variables, understand type inference, and work with common built-in types.
Constants and variables
Use let for a value that will not be reassigned and var for a value that can change.
Type inference and type annotations
Swift can infer a value’s type from its initial value, and you can write a type annotation when clarity is useful.
Numbers, booleans, and type conversion
Swift provides distinct types for integers, floating-point values, booleans, and text.
Module checkpoint: Declare a constant for a person’s name, a variable for a score, a Boolean completion flag, and a Double measurement. Print them using string interpolation and perform one explicit numeric conversion.
3. Expressions, decisions, and loops
BeginnerUse operators, conditional logic, switch, and loops to control how a Swift program executes.
Arithmetic and comparison operators
Operators combine values and produce results such as numbers or Boolean conditions.
Make decisions with if and switch
Use if for conditional branches and switch to select among patterns or values.
Repeat work with loops and ranges
for-in, while, and repeat-while loops provide different ways to repeat statements.
Module checkpoint: Write a program that classifies a numeric score, prints a message using switch, and uses a loop to display the first five positive integers. Test values at the boundaries of your conditions.
4. Optionals and safe value handling
BeginnerModel the presence or absence of a value explicitly and unwrap optionals safely.
Why optionals exist
An optional represents either a wrapped value or the absence of a value.
Unwrap optionals with optional binding
Optional binding safely makes a wrapped value available inside a scope only when it exists.
Optional chaining and nil-coalescing
Optional chaining safely accesses members of a value that may be absent, while ?? supplies a fallback.
Module checkpoint: Write a function that accepts an optional String and returns a useful greeting. Handle nil with optional binding or a default, and avoid force-unwrapping the input.
5. Functions, closures, and functional patterns
BeginnerBuild reusable behavior with functions and closures, and pass behavior as values.
Declare and call functions
Functions package reusable statements behind a named interface with inputs and an optional result.
Argument labels and default parameters
Swift function parameters can have external argument labels and default values.
Closures and higher-order functions
A closure is a self-contained block of functionality that can be stored, passed, and returned.
Module checkpoint: Create a function that converts minutes to seconds. Give one parameter a default value, then use map or filter with a closure to transform a small array.
6. Collections and strings
BeginnerStore groups of values with arrays, sets, and dictionaries, and work safely with Swift strings.
Work with arrays
An array stores values in an ordered sequence and allows access by index.
Use sets and dictionaries
Sets store unique values, while dictionaries associate keys with values.
Strings, characters, and Unicode
Swift String represents Unicode text and provides operations that respect extended grapheme clusters.
Module checkpoint: Build a small in-memory contact list using an array or dictionary. Add, search, and display entries, and handle missing dictionary keys safely.
7. Structs, enums, and value semantics
IntermediateModel domain concepts with custom value types, enumerations, and pattern matching.
Define structs and properties
A struct groups related data and behavior into a custom value type.
Enumerations and associated values
An enum defines a finite set of related cases and can carry additional data with a case.
Pattern matching and value semantics
Switch and if-case patterns inspect enum cases, while value types provide independent value semantics.
Module checkpoint: Model an order using a struct and an enum for its status. Include an associated value for a failure reason and write a switch that handles every status.
8. Classes, inheritance, and memory management
IntermediateUse reference types when identity and shared mutable state are needed, and understand automatic reference counting.
Classes and reference semantics
A class is a reference type that supports identity, shared references, and inheritance.
Initializers, inheritance, and overriding
Initializers create valid instances, while class inheritance allows a subclass to specialize a superclass.
ARC, weak references, and retain cycles
Automatic Reference Counting manages class instance lifetimes by tracking strong references.
Module checkpoint: Create a small class hierarchy with a base type and one subclass. Then draw a two-object reference graph and identify where a weak reference would prevent a retain cycle.
9. Protocols, extensions, and generics
IntermediateDesign flexible abstractions with protocols, add focused functionality with extensions, and write reusable generic code.
Define and adopt protocols
A protocol describes requirements that conforming types must provide.
Extend existing types
Extensions add computed properties, methods, initializers, and protocol conformance to existing types.
Generics and type constraints
Generics let functions and types work with multiple concrete types while preserving compile-time type information.
Module checkpoint: Define a protocol for values that can be displayed, conform two different structs to it, and write a generic function that accepts a collection of displayable values.
10. Error handling, Codable, and data persistence
IntermediateRepresent failures explicitly, encode and decode structured data, and read or write simple files.
Throwing functions and custom errors
A throwing function can report a failure using Swift’s typed error-handling mechanisms.
Handle and transform errors
Swift provides do-catch, optional conversion, and Result for expressing different error-handling needs.
Codable and basic file persistence
Codable enables models to be encoded and decoded by compatible encoders and decoders.
Module checkpoint: Create a Codable model for a study session. Encode it to JSON data, decode it back, and handle encoding or decoding failures without force-try.
11. Concurrency and networking
AdvancedUse async and await, tasks, actors, and URLSession to write responsive asynchronous Swift code.
Asynchronous functions with async and await
Swift async and await express operations that may suspend while waiting for work to complete.
Tasks, structured concurrency, and actors
Tasks represent asynchronous work, while actors help protect mutable state from concurrent access.
Fetch and decode data with URLSession
URLSession provides asynchronous APIs for network requests and can be combined with Codable for response decoding.
Module checkpoint: Design an async function that fetches JSON from an endpoint, validates the HTTP response, decodes a Codable model, and propagates failures. Explain where cancellation should be supported.
12. Packages, testing, and code organization
AdvancedOrganize code into reusable targets, test behavior, and apply access control and maintainable design.
Packages, targets, and dependencies
Swift Package Manager organizes source code into packages, targets, products, and dependencies.
Write unit tests
Unit tests check small units of behavior and help detect regressions as code changes.
Access control and maintainable design
Access control limits where declarations can be used and helps define stable module interfaces.
Module checkpoint: Create a small package with a library target and a test target. Add tests for a model or calculation, then make implementation details private while exposing a small public API.
13. SwiftUI and application architecture
AdvancedApply Swift foundations to declarative Apple-platform interfaces, state-driven views, navigation, and app structure.
Build interfaces with SwiftUI views
SwiftUI describes an interface as a hierarchy of views whose appearance depends on data and state.
State and data flow in SwiftUI
SwiftUI state tools keep views synchronized with the data that drives them.
Navigation and app architecture
Navigation containers and focused model layers help organize multi-screen applications.
Module checkpoint: Sketch a two-screen SwiftUI study planner. Identify the state each screen needs, decide which view owns the source of truth, and outline where persistence and network logic should live.