Skip to content
iamnoobs

Beginner to advanced · 13 modules · 39 lessons

Learn Swift: Beginner to Advanced

Learn Swift programming from the fundamentals through value types, protocols, memory management, concurrency, testing, and SwiftUI application development.

Who this is for: Beginners, students, and developers who want to build Swift applications, understand modern language features, and develop for Apple platforms.

Prerequisites: No prior Swift experience is required. Basic computer literacy is helpful. The core language examples are platform-neutral; the final module introduces SwiftUI for Apple-platform development.

Meet Swift and the Swift toolchain

What Swift is used for

Swift is a general-purpose programming language designed for safety, performance, and clear syntax.

Swift is used to build apps for Apple platforms and can also be used for command-line tools, server applications, and other systems. Its language features include type inference, optionals, value types, protocols, and structured concurrency.

Swift code is commonly compiled. The same language can be used in different project types, but available frameworks depend on the operating system and target platform. For example, SwiftUI is primarily used to build user interfaces for Apple platforms.

Guided example

Read through this example; code examples are for learning and are not executed on this site.

let message = "Hello, Swift!"
print(message)

Relevance quest · +10 XP

Which statement best describes Swift?

Choose your answer

Mark this lesson complete when you are ready.

Module checkpoint: Meet Swift and the Swift toolchain

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.

After this module, you can:

  • Describe Swift and common platforms where it is used.
  • Explain the edit, build, and run workflow.
  • Create a basic Swift program and recognize compiler feedback.

Full curriculum

What you will learn

1. Meet Swift and the Swift toolchain

Beginner

Understand where Swift runs, how source code is compiled, and how to create and execute a small program.

  1. What Swift is used for

    Swift is a general-purpose programming language designed for safety, performance, and clear syntax.

  2. Your first Swift program

    A Swift program can start with executable statements at the top level or use an explicit main entry point.

  3. 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

Beginner

Store information using constants and variables, understand type inference, and work with common built-in types.

  1. Constants and variables

    Use let for a value that will not be reassigned and var for a value that can change.

  2. 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.

  3. 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

Beginner

Use operators, conditional logic, switch, and loops to control how a Swift program executes.

  1. Arithmetic and comparison operators

    Operators combine values and produce results such as numbers or Boolean conditions.

  2. Make decisions with if and switch

    Use if for conditional branches and switch to select among patterns or values.

  3. 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

Beginner

Model the presence or absence of a value explicitly and unwrap optionals safely.

  1. Why optionals exist

    An optional represents either a wrapped value or the absence of a value.

  2. Unwrap optionals with optional binding

    Optional binding safely makes a wrapped value available inside a scope only when it exists.

  3. 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

Beginner

Build reusable behavior with functions and closures, and pass behavior as values.

  1. Declare and call functions

    Functions package reusable statements behind a named interface with inputs and an optional result.

  2. Argument labels and default parameters

    Swift function parameters can have external argument labels and default values.

  3. 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

Beginner

Store groups of values with arrays, sets, and dictionaries, and work safely with Swift strings.

  1. Work with arrays

    An array stores values in an ordered sequence and allows access by index.

  2. Use sets and dictionaries

    Sets store unique values, while dictionaries associate keys with values.

  3. 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

Intermediate

Model domain concepts with custom value types, enumerations, and pattern matching.

  1. Define structs and properties

    A struct groups related data and behavior into a custom value type.

  2. Enumerations and associated values

    An enum defines a finite set of related cases and can carry additional data with a case.

  3. 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

Intermediate

Use reference types when identity and shared mutable state are needed, and understand automatic reference counting.

  1. Classes and reference semantics

    A class is a reference type that supports identity, shared references, and inheritance.

  2. Initializers, inheritance, and overriding

    Initializers create valid instances, while class inheritance allows a subclass to specialize a superclass.

  3. 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

Intermediate

Design flexible abstractions with protocols, add focused functionality with extensions, and write reusable generic code.

  1. Define and adopt protocols

    A protocol describes requirements that conforming types must provide.

  2. Extend existing types

    Extensions add computed properties, methods, initializers, and protocol conformance to existing types.

  3. 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

Intermediate

Represent failures explicitly, encode and decode structured data, and read or write simple files.

  1. Throwing functions and custom errors

    A throwing function can report a failure using Swift’s typed error-handling mechanisms.

  2. Handle and transform errors

    Swift provides do-catch, optional conversion, and Result for expressing different error-handling needs.

  3. 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

Advanced

Use async and await, tasks, actors, and URLSession to write responsive asynchronous Swift code.

  1. Asynchronous functions with async and await

    Swift async and await express operations that may suspend while waiting for work to complete.

  2. Tasks, structured concurrency, and actors

    Tasks represent asynchronous work, while actors help protect mutable state from concurrent access.

  3. 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

Advanced

Organize code into reusable targets, test behavior, and apply access control and maintainable design.

  1. Packages, targets, and dependencies

    Swift Package Manager organizes source code into packages, targets, products, and dependencies.

  2. Write unit tests

    Unit tests check small units of behavior and help detect regressions as code changes.

  3. 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

Advanced

Apply Swift foundations to declarative Apple-platform interfaces, state-driven views, navigation, and app structure.

  1. Build interfaces with SwiftUI views

    SwiftUI describes an interface as a hierarchy of views whose appearance depends on data and state.

  2. State and data flow in SwiftUI

    SwiftUI state tools keep views synchronized with the data that drives them.

  3. 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.

Put it together

Swift capstone: Personal study planner

Build a small study planner that models subjects and study sessions, tracks completion, persists data with Codable, and presents the information through a SwiftUI interface. Organize the solution into focused model, service, and presentation components.

  1. 1Define value types for subjects, study sessions, and goals, and use enums for finite states such as session status.
  2. 2Implement validation and calculations with small functions, optionals, and explicit error handling.
  3. 3Use collections to add, search, filter, and summarize study sessions.
  4. 4Make the study-session model Codable and implement a persistence service that handles file errors.
  5. 5Create an asynchronous data-loading interface and explain how cancellation and shared state are handled.
  6. 6Build SwiftUI screens for a session list, session detail, and a simple form; define a clear source of truth for state.
  7. 7Add unit tests for calculations, validation, serialization, and important failure cases.
  8. 8Document the package structure, supported platform, accessibility considerations, and steps for building and testing the app.

Progress is saved in this browser when local storage is available. You can continue without an account; changing browsers or clearing browser data may remove saved progress. Examples are not executed by the site.