43 lessons

Swift Tutorial for Beginners

Learn Swift programming step by step, from your first program to structs, protocols, concurrency and SwiftUI, with Swift examples, exercises and quizzes for iOS beginners.

Browse all 43 lessons by stage

Lessons
43
Code examples
94
Exercises
143
Quiz questions
161

Swift course at a glance

Who it's for

Complete beginners who want to build iPhone, iPad or Mac apps, developers coming from another language, and anyone curious about Swift on the server or the command line.

Prerequisites

None for the core lessons. Basic computer skills are enough, and the in-depth guides list the lessons to finish before you start them.

What you need

A Mac with Xcode for app development, or Swift Playgrounds on an iPad or Mac. The language lessons also run with the Swift toolchain on Linux and Windows.

How long it takes

About two months for the 25 core lessons at five hours a week, plus extra time for the in-depth guides and a first small SwiftUI app.

Swift roadmap: beginner to advanced

Work through the 25 core chapters in the first three stages in order, then use the reference stages to go deeper. Each reference lesson links to its prerequisite and includes examples, practice and a quiz.

2

Intermediate

Arrays, dictionaries and sets, closures, structs, classes, enums, protocols, extensions and error handling.

  1. 9ArraysStore ordered lists of values in arrays, read and change items safely, add and remove items, and use built-in methods to search, sort and slice.
  2. 10Dictionaries & SetsLook up values by key with dictionaries, keep unique values with sets, update and remove entries, loop over them in a predictable order, and count and group data.
  3. 11ClosuresWrite functions as values with closures, shorten them with type inference, $0 and trailing closure syntax, and transform collections with map, filter, reduce, sorted and compactMap.
  4. 12StructsModel data with structs: stored and computed properties, methods, mutating methods, memberwise and custom initializers, property observers and why structs are value types.
Show all 9 lessonsShow fewer
  1. 13ClassesUse classes when you need shared identity and inheritance: initializers, reference semantics, identity with ===, subclassing with override and super, final, and choosing between classes and structs.
  2. 14EnumsModel a fixed set of options with enums, attach raw values and associated data, add computed properties and methods, loop over cases, and handle every case with switch.
  3. 15ProtocolsDescribe abilities with protocols, make structs, classes and enums conform, share default behaviour with protocol extensions, and use standard protocols like Equatable, Comparable and Identifiable.
  4. 16ExtensionsAdd new methods, computed properties, initializers and protocol conformances to any type, including Apple's own, with extensions, and use them to organise code.
  5. 17Error HandlingReport and handle problems with Swift's error handling: define errors with enums, throw them, catch them with do-catch, convert them to optionals with try?, and use Result and defer.
3

Advanced

Generics, memory and ARC, concurrency, Codable and JSON, SwiftUI basics, state, lists and navigation, and testing.

  1. 18GenericsWrite functions and types that work with any type while staying type-safe, using generic parameters, constraints, where clauses, associated types and some.
  2. 19Memory & ARCUnderstand how Automatic Reference Counting frees class instances, spot strong reference cycles, and break them with weak, unowned and [weak self] in closures.
  3. 20ConcurrencyRun slow work without freezing your app using async and await, start work with Task, run jobs in parallel with async let and task groups, and protect shared state with actors and @MainActor.
  4. 21Codable & JSONTurn JSON into Swift structs and back with Codable, JSONDecoder and JSONEncoder, rename keys with CodingKeys, handle dates, optional fields and nested data, and decode API responses.
Show all 8 lessonsShow fewer
  1. 22SwiftUI BasicsBuild your first SwiftUI interfaces from views like Text, Image and Button, arrange them with VStack, HStack and ZStack, style them with modifiers, and preview them live in Xcode.
  2. 23SwiftUI StateMake SwiftUI screens interactive with @State, share values with child views through @Binding, keep app data in @Observable models, and read shared objects from the environment.
  3. 24Lists & NavigationShow collections with List and ForEach, move between screens with NavigationStack and NavigationLink, present sheets and alerts, add swipe actions and search, and organise apps with TabView.
  4. 25TestingCheck your code automatically with Swift Testing's @Test and #expect, test errors and async code, run one test with many inputs, replace dependencies with fakes, and read XCTest code.
4

Language reference

Access control, initialisation, lazy and wrapped properties, subscripts and key paths, type casting, some and any, collections, Unicode strings and regex.

  1. 26Access controlExpose a deliberate interface while hiding mutable details, and distinguish file, module, package and external access.
  2. 27Initialization rulesBuild valid values with failable initializers, separate designated and convenience paths, and understand subclass initialization obligations.
  3. 28Lazy properties and wrappersDelay expensive setup until access and use wrappers for repeated property policies without confusing caching, validation and synchronization.
  4. 29Subscripts and key pathsDesign clear indexed access, return absence deliberately, and use typed key paths to select properties without string-based field names.
Show all 9 lessonsShow fewer
  1. 30Type castingCheck runtime types, use conditional downcasts, and narrow uncertain values into typed models without turning casts into conversions.
  2. 31some and anyDistinguish a hidden fixed concrete type from a container holding varying conforming values, and choose the right abstraction for callers.
  3. 32Collection protocols and lazyWrite algorithms for the capabilities they need, distinguish repeatable collections from sequences, and understand slice indices and lazy work.
  4. 33Unicode and text indicesWork with user-perceived characters safely, distinguish scalar and encoding views, and convert ranges across text APIs explicitly.
  5. 34Native RegexMatch whole records or search larger text, use typed capture results, and validate parsed values independently from the pattern.

What is Swift?

Swift is the programming language Apple created for building apps on iPhone, iPad, Mac, Apple Watch, Apple TV and Vision Pro. It's fast, modern and designed to be safe: optionals make missing values explicit, the compiler checks types carefully, and Swift 6 even catches data races before your app runs. Swift is also open source and runs on Linux and Windows, where it's used for servers and command-line tools.

Swift reads cleanly, which makes it a friendly first language. You can try it in Xcode's playgrounds or the Swift Playgrounds app on iPad and Mac, and see results as you type.

This tutorial has three stages. The beginner stage covers your first program, variables and constants, numbers, strings, optionals, decisions with if and switch, loops and functions. The intermediate stage teaches arrays, dictionaries and sets, closures, structs, classes, enums, protocols, extensions and error handling. The advanced stage covers generics, memory management with ARC, async/await concurrency, JSON with Codable, SwiftUI views, state and navigation, and automated testing.

Every lesson has small examples with their output, common mistakes, exercises and a quiz. If you're also interested in Android, the Kotlin tutorial covers a language with many of the same ideas.

How to follow this course

Work through the 25 core lessons in order, because each one builds on the last. After that, the in-depth guides answer the questions real apps raise. The language guides cover access control, initialisation rules, lazy and property wrappers, subscripts and key paths, type casting, some and any, lazy collections, Unicode string indices and native regex. The tools and data guides cover Swift packages, dates and time zones, saving Codable data to files and URLSession networking. The concurrency and app guides cover async streams, Swift 6 Sendable checking, actors, SwiftUI forms and SwiftData. Each guide lists the core lessons to finish first.

What you will learn

10 practical skills, built one lesson at a time

  • Write and run Swift code in Xcode playgrounds and projects
  • Use constants, variables, numbers and strings with string interpolation
  • Handle missing values safely with optionals, if let, guard let and ??
  • Control programs with if, switch, loops and ranges
  • Write functions with argument labels, default values and closures
  • Store data in arrays, dictionaries and sets, and transform it with map and filter
  • Model data with structs, classes, enums, protocols and extensions
  • Handle errors with throws, do-catch and Result
  • Write concurrent code with async/await, tasks and actors, and decode JSON with Codable
  • Build SwiftUI screens with state, lists and navigation, and test your code
43 lessons94 examples143 exercises

Practise Swift your way

Learning sticks when you use it. Pick a mode.

Swift FAQ

Is Swift good for beginners?

Yes. Swift's syntax is clear and readable, and its safety features catch many mistakes before your code runs. Xcode playgrounds and the Swift Playgrounds app show results instantly, which makes experimenting easy.

Do I need a Mac to learn Swift?

To build iPhone and Mac apps you need a Mac with Xcode. To learn the language itself, you can also use Swift Playgrounds on an iPad, or install Swift on Linux or Windows. The beginner and intermediate lessons in this course work anywhere Swift runs.

Should I learn SwiftUI or UIKit?

Start with SwiftUI. It's Apple's modern framework, it's where new features appear first, and it's much quicker to learn. UIKit is still found in many existing apps, so learning it later is useful if you join a team with an older codebase.

How long does it take to learn Swift?

With about an hour a day, most beginners finish the beginner stage in two weeks and the whole course in two to three months. Building a small app alongside the lessons, such as a to-do list or a tip calculator, is the fastest way to make it stick.

Should I learn Swift or Kotlin for mobile apps?

Swift is the language for Apple's platforms and Kotlin is the language for Android. Most developers start with the platform they use themselves. The two languages share many ideas, such as optionals and null safety, closures and value types, so learning the second is much quicker. See the Kotlin tutorial too.

Is this Swift course free?

Yes. All 25 core lessons, the 18 in-depth guides, the exercises, the quiz and the cheat sheet are free, with no account or sign-up needed.

Which Swift version does the course use?

The examples target Swift 6 with Xcode 16 or later. Most language lessons also work in Swift 5.9 and 5.10; the concurrency guides point out where Swift 6's strict data-race checking changes what the compiler accepts.

Can I publish an App Store app after this course?

The course gives you the Swift and SwiftUI foundations an app needs. Publishing also needs an Apple Developer Program membership, app icons, testing on real devices and App Store review, which are outside the course but much easier once the language is familiar.

Is Swift used outside Apple platforms?

Yes. Swift is open source and runs on Linux and Windows, where it's used for server apps with frameworks such as Vapor, command-line tools and embedded projects. SwiftUI and most Apple frameworks are only available on Apple platforms.

More tutorials