Mobile development

Stage 1 · Lesson 3 of 10

Functions and closures

Swift fundamentals

functions have argument labels that make calls read like sentences, as in move(from: a, to: b). Write _ to leave a label out. Parameters can have default values.

are functions without a name. When a closure is the last argument, you write it after the brackets, as in names.sorted { $0 < $1 }. is built on this trailing closure style.

A closure stored to run later, such as a , is marked @escaping. It holds on strongly to the variables it uses, keeping them in memory.

Common trapa class that stores a closure which captures self, creating a retain cycle that keeps both in memory for ever; [weak self] breaks it.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with

  • CourseFree
    100 Days of SwiftUI

    Paul Hudson (Hacking with Swift) · Beginner

    Days 1 to 15 teach Swift, with a checkpoint exercise every other day

Practise

  • Dart, TypeScript, Kotlin and Swift tracks with small exercises and free mentor feedback

Keep handy

Also worth your time

Mark this stage as not done?