<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">It seems like my original (simplified) examples didn't clearly highlight what the problem I'm focused on solving.</div><div class=""><br class=""></div><div class="">Enums get large, and they get complicated because the code for each case gets sliced up and scattered across many functions. It becomes a "one of these things is not like the other" situation because writing functions inside enums is unlike writing functions in any other part of Swift code.</div><div class=""><br class=""></div><div class="">Also, to be clear, my goal is _not_ code brevity. It is coherence, the property where related code is located together. Some increase in code verbosity is acceptable to make code more coherent, since that leads to long-term maintainability.</div><div class=""><br class=""></div><div class="">I've pulled out a few of the larger enums I've seen in code to try to illustrate this. Along the way, I've made a few alterations based on the comments I've seen come through. (Rien & Robert: I've pushed the definitions inside the declaration, to ensure they don't end up in other files since that was never my intention; Rien & Daniel: I've altered the syntax to open a brace right after the case declaration making everything outside it the default, and I like that better).</div><div class=""><br class=""></div><div class="">Here's an enum used to consolidate the descriptions of UI elements for a screen, allowing the datasource to alter their order, presentation, and visibility while keeping the set of possible fields clean and finite. These enum values are used much like singletons.</div></div><div class=""><br class=""></div><div class=""><pre style="font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(241, 240, 240); background-position: initial initial; background-repeat: initial initial;" class=""><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">enum</span> OneOnOneField<span style="color: rgb(128, 96, 48);" class="">:</span> Int <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">agenda</span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> summary</span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> date</span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> notes</span>
<span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">struct</span><span style="color: rgb(0, 125, 69);" class=""> Info <span style="color: rgb(128, 96, 48);" class="">{</span>
var title<span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span>
var placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span>
var image<span style="color: rgb(128, 96, 48);" class="">:</span> UIImage
<span style="color: rgb(128, 96, 48);" class="">}</span>
var info<span style="color: rgb(128, 96, 48);" class="">:</span> Info <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> self <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span>agenda<span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> Info<span style="color: rgb(128, 96, 48);" class="">(</span>
title<span style="color: rgb(128, 96, 48);" class="">:</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Agenda</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field header</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">,</span>
placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Add an agenda</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field placeholder</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">,</span>
image<span style="color: rgb(128, 96, 48);" class="">: #imageLiteral</span><span style="color: rgb(128, 96, 48);" class="">(</span>resourceName<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Agenda-Small</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span>summary<span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> Info<span style="color: rgb(128, 96, 48);" class="">(</span>
title<span style="color: rgb(128, 96, 48);" class="">:</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Summary</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field header</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">,</span>
placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Add a summary</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field placeholder</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">,</span>
image<span style="color: rgb(128, 96, 48);" class="">: #imageLiteral</span><span style="color: rgb(128, 96, 48);" class="">(</span>resourceName<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Summary-Small</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span>date<span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> Info<span style="color: rgb(128, 96, 48);" class="">(</span>title<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> image<span style="color: rgb(128, 96, 48);" class="">:</span> UIImage<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span>notes<span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> Info<span style="color: rgb(128, 96, 48);" class="">(</span>title<span style="color: rgb(128, 96, 48);" class="">:</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Personal Notes</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Title for personal notes screen</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">,</span> placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> image<span style="color: rgb(128, 96, 48);" class="">:</span> UIImage<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span></span></pre><div class="">Consolidating them could instead look something like this:</div></div><div class=""><br class=""></div><div class=""><pre style="font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(241, 240, 240); background-position: initial initial; background-repeat: initial initial;" class=""><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">enum</span> OneOnOneField<span style="color: rgb(128, 96, 48);" class="">:</span> Int <span style="color: rgb(128, 96, 48);" class="">{</span>
var title<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 0, 0);" class="">"</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
var placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 0, 0);" class="">"</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
var image<span style="color: rgb(128, 96, 48);" class="">:</span> UIImage <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> UIImage<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">agenda </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var title</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Agenda</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field header</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
var placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Add an agenda</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field placeholder</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
var image<span style="color: rgb(128, 96, 48);" class="">:</span> UIImage <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 96, 48);" class="">#imageLiteral</span><span style="color: rgb(128, 96, 48);" class="">(</span>resourceName<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Agenda-Small</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">summary </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var title</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Summary</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field header</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
var placeholder<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Add a summary</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">One on one field placeholder</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
var image<span style="color: rgb(128, 96, 48);" class="">:</span> UIImage <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 96, 48);" class="">#imageLiteral</span><span style="color: rgb(128, 96, 48);" class="">(</span>resourceName<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Summary-Small</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">date</span>
<span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> notes </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var title</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span> <span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> NSLocalizedString<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Personal Notes</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">,</span> comment<span style="color: rgb(128, 96, 48);" class="">:</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Title for personal notes screen</span><span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span></pre><div class="">Here's an enum that implements the basics of a state machine for OAuth 2 token use, refreshing, and login. Some of its cases have associated values and some don't.</div></div><div class=""><br class=""></div><div class=""><pre style="font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(241, 240, 240); background-position: initial initial; background-repeat: initial initial;" class=""><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">enum</span> TokenState<span style="color: rgb(128, 96, 48);" class="">:</span> State <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">loading</span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> none</span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> expired</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">Date</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> untested</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">:</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 0, 64);" class="">String</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case</span><span style="color: rgb(0, 125, 69);" class=""> validated</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">:</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 0, 64);" class="">String</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var description</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> self <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">loading</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Loading token from disk</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">none</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">No token found</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">expired</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">at</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Expired at </span><span style="color: rgb(15, 105, 0);" class="">\(</span><span style="color: rgb(230, 0, 0);" class="">at)</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">untested</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Received token </span><span style="color: rgb(15, 105, 0);" class="">\(</span><span style="color: rgb(230, 0, 0);" class="">token), but it hasn't been tested.</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">validated</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Token </span><span style="color: rgb(15, 105, 0);" class="">\(</span><span style="color: rgb(230, 0, 0);" class="">token) has been validated.</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
mutating func react<span style="color: rgb(128, 96, 48);" class="">(</span>to event<span style="color: rgb(128, 96, 48);" class="">:</span> Event<span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> self <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">loading</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenNotFound</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>none
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let expired as TokenExpired</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>expired<span style="color: rgb(128, 96, 48);" class="">(</span>expired<span style="color: rgb(128, 96, 48);" class="">.</span>at<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let loaded as TokenLoaded</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>untested<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> loaded<span style="color: rgb(128, 96, 48);" class="">.</span>token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">none</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let loggedIn as UserLoggedIn</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>untested<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> loggedIn<span style="color: rgb(128, 96, 48);" class="">.</span>token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">expired</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let refreshed as TokenRefreshed</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>untested<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> refreshed<span style="color: rgb(128, 96, 48);" class="">.</span>token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenRefreshErrored</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>none
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">untested</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as UserLoaded</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>validated<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenRejected</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>expired<span style="color: rgb(128, 96, 48);" class="">(</span>at<span style="color: rgb(128, 96, 48);" class="">:</span> Date<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(128, 96, 48);" class="">.</span><span style="color: rgb(0, 125, 69);" class="">validated</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenRejected</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>expired<span style="color: rgb(128, 96, 48);" class="">(</span>Date<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as UserLoggedOut</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>none
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">static</span> var initialState<span style="color: rgb(128, 96, 48);" class="">:</span> TokenState <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 96, 48);" class="">.</span>loading
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span></pre><div class="">After consolidation, this becomes:</div></div><div class=""><br class=""></div><div class=""><pre style="font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(241, 240, 240); background-position: initial initial; background-repeat: initial initial;" class=""><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">enum</span> TokenState<span style="color: rgb(128, 96, 48);" class="">:</span> State <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">static</span> var initialState<span style="color: rgb(128, 96, 48);" class="">:</span> TokenState <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 96, 48);" class="">.</span>loading
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">loading </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var description</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Loading token from disk</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
mutating func react<span style="color: rgb(128, 96, 48);" class="">(</span>to event<span style="color: rgb(128, 96, 48);" class="">:</span> Event<span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenNotFound</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>none
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let expired as TokenExpired</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>expired<span style="color: rgb(128, 96, 48);" class="">(</span>at<span style="color: rgb(128, 96, 48);" class="">:</span> expired<span style="color: rgb(128, 96, 48);" class="">.</span>at<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let loaded as TokenLoaded</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>untested<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> loaded<span style="color: rgb(128, 96, 48);" class="">.</span>token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">none </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var description</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">No token found</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
mutating func react<span style="color: rgb(128, 96, 48);" class="">(</span>to event<span style="color: rgb(128, 96, 48);" class="">:</span> Event<span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let loggedIn as UserLoggedIn</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>untested<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> loggedIn<span style="color: rgb(128, 96, 48);" class="">.</span>token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">expired</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">at</span><span style="color: rgb(128, 96, 48);" class="">:</span><span style="color: rgb(0, 125, 69);" class=""> Date</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var description</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Expired at </span><span style="color: rgb(15, 105, 0);" class="">\(</span><span style="color: rgb(230, 0, 0);" class="">at)</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
mutating func react<span style="color: rgb(128, 96, 48);" class="">(</span>to event<span style="color: rgb(128, 96, 48);" class="">:</span> Event<span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">let refreshed as TokenRefreshed</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>untested<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> refreshed<span style="color: rgb(128, 96, 48);" class="">.</span>token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenRefreshErrored</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>none
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">untested</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">:</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 0, 64);" class="">String</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var description</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Received token </span><span style="color: rgb(15, 105, 0);" class="">\(</span><span style="color: rgb(230, 0, 0);" class="">token), but it hasn't been tested.</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
mutating func react<span style="color: rgb(128, 96, 48);" class="">(</span>to event<span style="color: rgb(128, 96, 48);" class="">:</span> Event<span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as UserLoaded</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>validated<span style="color: rgb(128, 96, 48);" class="">(</span>token<span style="color: rgb(128, 96, 48);" class="">:</span> token<span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenRejected</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>expired<span style="color: rgb(128, 96, 48);" class="">(</span>at<span style="color: rgb(128, 96, 48);" class="">:</span> Date<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">validated</span><span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(0, 125, 69);" class="">token</span><span style="color: rgb(128, 96, 48);" class="">:</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 0, 64);" class="">String</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(0, 125, 69);" class=""> </span><span style="color: rgb(128, 96, 48);" class="">{</span><span style="color: rgb(0, 125, 69);" class=""></span>
<span style="color: rgb(0, 125, 69);" class=""> var description</span><span style="color: rgb(227, 74, 220);" class="">:</span> <span style="color: rgb(128, 0, 64);" class="">String</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">return</span> <span style="color: rgb(128, 0, 0);" class="">"</span><span style="color: rgb(230, 0, 0);" class="">Token </span><span style="color: rgb(15, 105, 0);" class="">\(</span><span style="color: rgb(230, 0, 0);" class="">token) has been validated.</span><span style="color: rgb(128, 0, 0);" class="">"</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
mutating func react<span style="color: rgb(128, 96, 48);" class="">(</span>to event<span style="color: rgb(128, 96, 48);" class="">:</span> Event<span style="color: rgb(128, 96, 48);" class="">)</span> <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">switch</span> event <span style="color: rgb(128, 96, 48);" class="">{</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as TokenRejected</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>expired<span style="color: rgb(128, 96, 48);" class="">(</span>at<span style="color: rgb(128, 96, 48);" class="">:</span> Date<span style="color: rgb(128, 96, 48);" class="">(</span><span style="color: rgb(128, 96, 48);" class="">)</span><span style="color: rgb(128, 96, 48);" class="">)</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">case </span><span style="color: rgb(0, 125, 69);" class="">_ as UserLoggedOut</span><span style="color: rgb(227, 74, 220);" class="">:</span>
self <span style="color: rgb(128, 96, 48);" class="">=</span> <span style="color: rgb(128, 96, 48);" class="">.</span>none
<span style="color: rgb(227, 74, 220);" class=""> </span><span style="color: rgb(64, 0, 0); font-weight: bold;" class="">default</span><span style="color: rgb(227, 74, 220);" class="">:</span>
<span style="color: rgb(64, 0, 0); font-weight: bold;" class="">break</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span>
<span style="color: rgb(128, 96, 48);" class="">}</span></pre><div class=""><br class=""></div></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 8, 2017, at 12:22 PM, Derrick Ho via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Currently we can write a helper method to aid in getting the values inside the enum associated value. Below is a fully working implementation:<div class=""><br class=""></div><div class="">```</div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">enum</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Package {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> box(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">String</span><span style="font-variant-ligatures:no-common-ligatures" class="">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> circular(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">String</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span></span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> associated: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Associated</span><span style="font-variant-ligatures:no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Associated</span><span style="font-variant-ligatures:no-common-ligatures" class="">(package: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span>}</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;min-height:13px" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span></span><br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">struct</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Associated {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> box: (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">String</span><span style="font-variant-ligatures:no-common-ligatures" class="">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span><span style="font-variant-ligatures:no-common-ligatures" class="">)?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> circular: (</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">String</span><span style="font-variant-ligatures:no-common-ligatures" class="">)?</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(package: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Package</span><span style="font-variant-ligatures:no-common-ligatures" class="">) {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">switch</span><span style="font-variant-ligatures:no-common-ligatures" class=""> package {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">box</span><span style="font-variant-ligatures:no-common-ligatures" class="">(let b):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">box</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = b</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                                </span></span><span style="font-variant-ligatures:no-common-ligatures" class="">circular</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                        </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">case</span><span style="font-variant-ligatures:no-common-ligatures" class=""> .</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">circular</span><span style="font-variant-ligatures:no-common-ligatures" class="">(let b):</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">box</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                                </span></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">circular</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = b</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                        </span>}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">                </span>}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><span class="inbox-Apple-tab-span" style="white-space:pre">        </span>}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> b = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Package</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">box</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"square"</span><span style="font-variant-ligatures:no-common-ligatures" class="">, </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">5</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">b</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">box</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// Optional("square")</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">b</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">box</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// Optional(5)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">b</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">circular</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; min-height: 13px;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(186,45,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> c = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Package</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">circular</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"round"</span><span style="font-variant-ligatures:no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">c</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">box</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">0</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">c</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">box</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// nil</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">c</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">circular</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// Optional("round")</span></div></div><div class="">```</div><div class=""><br class=""></div><div class="">I had to wedge in a special type called "Associated" and had to write some boiler-plate code to get this effect. It is quite predictable and can probably be done under the hood. I would of course prefer syntactic sugar to simplify it and turn</div><div class="">```</div><div class=""><span style="color:rgb(79,129,135);font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">b</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">.</span><span style="color:rgb(79,129,135);font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">associated</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">.</span><span style="color:rgb(79,129,135);font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">box</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures" class="">?.</span><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">0</span><br class=""></div><div class="">```</div><div class=""><font face="menlo" class=""><span style="font-size:11px" class="">into </span></font></div><div class=""><span style="font-size:11px;font-variant-ligatures:no-common-ligatures" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">```</span></span></div><div class=""><span style="font-family:menlo;font-size:11px;font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class=""><span style="color:rgb(79,129,135);font-variant-ligatures:no-common-ligatures" class="">b</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="color:rgb(79,129,135);font-variant-ligatures:no-common-ligatures" class="">box</span><span style="font-variant-ligatures: no-common-ligatures;" class="">?.</span><span style="font-variant-ligatures:no-common-ligatures" class="">0</span><br class=""></span></div><div class=""><span style="font-size:11px;font-variant-ligatures:no-common-ligatures" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">```</span></span></div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Sun, Jan 8, 2017 at 1:05 PM David Sweeris via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">On Jan 8, 2017, at 06:53, Karim Nassar via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a>> wrote:<br class="gmail_msg"><br class="gmail_msg"></div><blockquote type="cite" class="gmail_msg"><div class="gmail_msg"><div style="word-wrap:break-word" class="gmail_msg"><div class="gmail_msg">One area of enums that I’d love to see some sugar wrapped around (and perhaps this has already been discussed previously?) is extracting associated values.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">There are many times where, given an enum like:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg">enum Feedback {</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case ok</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case info(String)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case warning(String, Location)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case error(String, Location)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">I’d love it if we could tag the associated values with some semantic accessor, perhaps borrowed from tuples:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><div class="gmail_msg"><font face="Menlo" class="gmail_msg">enum Feedback {</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case ok</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case info(msg: String)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case warning(msg: String, loc: Location)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>case error(msg: String, loc: Location)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">then:</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg">let foo = self.getSomeFeedback() // -> Feedback</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg">if let msg = foo.msg { // since not all cases can hold a ‘msg’ .msg is an Optional</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg"><span class="m_5236553814310986016Apple-tab-span gmail_msg" style="white-space:pre-wrap">        </span>print(foo)</font></div><div class="gmail_msg"><font face="Menlo" class="gmail_msg">}</font></div></div></div></blockquote><br class="gmail_msg"></div><div dir="auto" class="gmail_msg"><div class="gmail_msg">Can't remember if it's come up before, but +1. I can't count how many times I've written something like:</div><div class="gmail_msg">enum Foo : CustomStringConvertible {</div><div class="gmail_msg"> case c1(T1)</div><div class="gmail_msg"> case c2(T2)</div><div class="gmail_msg"> ...</div><div class="gmail_msg"> case cN(TN)</div></div><div dir="auto" class="gmail_msg"><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg"> var description: String {</div><div class="gmail_msg"> switch self {</div></div><div dir="auto" class="gmail_msg"><div class="gmail_msg"> case .c1(let val): return "\(val)"</div><div class="gmail_msg"><div class="gmail_msg"><span style="background-color:rgba(255,255,255,0)" class="gmail_msg"> case .c2(let val): return "\(val)"</span></div></div><div class="gmail_msg"> ...</div><div class="gmail_msg"><div class="gmail_msg"><span style="background-color:rgba(255,255,255,0)" class="gmail_msg"> case .cN(let val): return "\(val)"</span></div></div><div class="gmail_msg"> }</div><div class="gmail_msg"> }</div><div class="gmail_msg">}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Being able to simplify that to:</div><div class="gmail_msg">var description: String {</div><div class="gmail_msg"> let nilDesc = "some appropriate description"</div><div class="gmail_msg"> return "\(self.0 ?? nilDesc)"</div><div class="gmail_msg">}</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">Would be great.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">- Dave Sweeris </div></div>_______________________________________________<br class="gmail_msg">
swift-evolution mailing list<br class="gmail_msg">
<a href="mailto:swift-evolution@swift.org" class="gmail_msg" target="_blank">swift-evolution@swift.org</a><br class="gmail_msg">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" class="gmail_msg" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="gmail_msg">
</blockquote></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>