Evaluating Case-Binding Syntax

Swift case binding is one of the least straightforward components of the entire language. Case binding enables you to match an enumeration case and then bind that case’s associated values to new constants and variables. Where you place those let and var keywords to bind case values involves nontrivial choices.

Safety and consistency play important roles in these decisions. You must choose whether to favor readability or error prevention, even though the likelihood of errors is quite small.

This section explores two distinct styles—external and internal case binding—and details the advantages of each. I recommend you adopt a consistent internal style, which was not my practice prior to writing this book. In researching ...

Get Swift Style now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.