Module 05 of 12

Functions, Closures & Optionals

Lessons

About This Module

This module covers the three Swift features you'll lean on in every app you write: functions to package up reusable code, closures to pass behavior around, and optionals to handle values that might be missing.

You'll learn how to define and call functions with parameters and return values, then see how closures work as unnamed functions you can store in variables and hand to other functions. Finally, you'll learn how Swift's optionals keep your code safe from crashes, and how to unwrap them properly.

Each topic has two different explanations, so if one doesn't click the other might. Every clip is cut to just the relevant chapter of a longer course. When you're ready, continue on to Structs, Classes & Protocols.

Lessons

6 clips
01

Functions in Swift (Clip 1)

Define and call functions, pass parameters, return values, and reuse code instead of repeating it.

02

Functions in Swift (Clip 2)

A second, shorter walkthrough of defining and using functions.

03

Closures in Swift (Clip 1)

What closures are, how to store them in variables, and how to pass them to other functions.

04

Closures in Swift (Clip 2)

A quick second take on closure syntax and how closures are used in practice.

05

Optionals in Swift (Clip 1)

Why Swift has optionals, what nil means, and how to unwrap values safely.

06

Optionals in Swift (Clip 2)

An extended look at optionals and the different ways to unwrap them.