0Pricing
Swift Academy · Lesson

Indirect Enums and Recursive Structures

Building linked lists and trees with indirect enum cases.

Welcome

An `indirect` enum case stores its associated value behind a pointer, enabling recursive data structures like linked lists, trees, and expression trees.

Why indirect is Needed

Without `indirect`, an enum that references itself would have infinite size: ```swift enum List { case empty case node(T, List) // ❌ recursive without size bound } ``` `indirect` adds a heap allocation so the size is just a pointer.

All lessons in this course

  1. Raw Values and CaseIterable
  2. Associated Values for Rich Data
  3. Indirect Enums and Recursive Structures
  4. Modeling State Machines with Enums
← Back to Swift Academy