Mobile development

Stage 1 · Lesson 6 of 10

Protocols and extensions

Swift fundamentals

A lists the properties and methods a type must provide. It is like an interface in other languages, and , classes and enums can all conform to one. You will use standard protocols constantly.

Equatable gives you ==. Hashable lets a type go in sets and be a key. Identifiable is needed for items in a List, and Codable turns values into JSON and back, which you will need later for .

An extension adds methods to any type, even ones you did not write. A protocol extension gives every type that conforms a default version of a method. SwiftUI's View is itself a protocol.

Common trapdesigning big protocol hierarchies up front; start with concrete types and add a protocol when two types genuinely share behaviour.

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?