|

Series

#MOLECULES OF SWIFT

A small piece of Swift, taken apart.

What is this series?

Swift has many small features that are easy to learn in isolation but much more interesting when they start working together.

Molecules of Swift takes those pieces apart: language features, standard-library tools, patterns, compiler behavior, and small techniques that can make Swift code shorter, clearer, and more expressive.

Each article focuses on one idea. Not just what the syntax does, but where it fits, what it composes with, and when another approach is better.

The series starts with Swift fundamentals and gradually moves into more advanced territory. Every article stands on its own, while together they build a practical path toward deeper Swift fluency.

  1. Associated Values: Put Data Where It Belongs
    - 8 min read

    Model Swift enum cases with their own data, extract associated values with patterns, and understand what this design does and does not guarantee.

  2. switch: Let Exhaustiveness Work for You
    - 8 min read

    Use exhaustive Swift switch matching to model every state, bind associated values, and understand when a default branch hides changes.

  3. for case and where: Filter While You Iterate
    - 8 min read

    Use Swift for case to select matching values during iteration, bind associated data, and add precise where conditions without hiding the loop's intent.

  4. if case and guard case: Match One Shape Without a switch
    - 10 min read

    Match one Swift enum case, bind its associated values, add conditions, and decide when guard case or an exhaustive switch is clearer.

  5. Nil Coalescing: Provide Defaults Without Branching
    - 7 min read

    See how Swift's nil-coalescing operator chooses defaults lazily, composes with optional chaining, and differs from validation and dictionary insertion.

  6. Optional Chaining: Let Absence Flow Through an Expression
    - 5 min read

    Follow optional values through Swift properties, calls, and subscripts—and learn what optional chaining skips, returns, and cannot protect.

  7. Optional Binding: Turn an Optional Into a Value
    - 5 min read

    Learn how Swift optional binding creates safe local values, combines checks, and controls where unwrapped values are available.

  8. guard: Keep the Main Path Flat
    - 4 min read

    Use Swift guard to state requirements early, keep successful optional bindings in scope, and leave the main path easy to follow.

  9. Tuple Patterns: Destructure Values Where You Use Them
    - 5 min read

    Use Swift tuple patterns to take tuples apart, ignore values you do not need, and match several values at once.

  10. Tuples: Group Values Without Creating a Type
    - 6 min read

    Swift tuples give a few related values a useful local shape without forcing every temporary relationship into a new named type.