title: How to access a Swift enum associated value outside of a switch statement
body: <p>Consider:</p>
  
  <pre><code>enum Line {
      case    Horizontal(CGFloat)
      case    Vertical(CGFloat)
  }
  
  let leftEdge             =  Line.Horizontal(0.0)
  let leftMaskRightEdge    =  Line.Horizontal(0.05)
  </code></pre>
  
  <p>How can I access, say, <code>lefEdge</code>'s associated value, directly, without using a switch statement?</p>
  
  <pre><code>let noIdeaHowTo          = leftEdge.associatedValue + 0.5
  </code></pre>
  
  <p>This doesn't even compile!</p>
  
  <p>I had a look at <a href="https://stackoverflow.com/questions/25880789/how-to-get-a-swift-enums-associated-value-regardless-of-the-enum-case">these</a> <a href="https://stackoverflow.com/questions/24263539/accessing-an-enumeration-association-value-in-swift">SO</a> <a href="https://stackoverflow.com/questions/29807402/how-should-i-implement-default-associated-values-with-swift-enums">questions</a> but none of the answers seem to address this issue.</p>
  
  <p>The <code>noIdeaHowTo</code> non compiling line above should really be that one-liner, but because the <code>associated value</code> can be any type, I fail to even see how user code could write even a "generic" get or associatedValue method in le enum itself.</p>
  
  <p>I ended up with this, but it is gross, and needs me to revisit the code each time I add/modify a case ...</p>
  
  <pre><code>enum Line {
      case    Horizontal(CGFloat)
      case    Vertical(CGFloat)
  
      var associatedValue: CGFloat {
          get {
              switch self {
                  case    .Horizontal(let value): return value
                  case    .Vertical(let value): return value
              }
          }
      }
  }
  </code></pre>
  
  <p>Any pointer anyone?</p>