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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access