title: Mapping swift enum with associated values
body: <p>Let say we have an enum with associated value types. In the example below the two value types are simple object that hold an image and a url to  share.</p>
  
  <pre><code>enum Content {
    case Image(ShareableImage)
    case Video(ShareableVideo)
  }
  </code></pre>
  
  <p>Now let's have an array of video and image cases.</p>
  
  <pre><code>let media: [Content] = [*a lot of enum cases inside here*]  
  </code></pre>
  
  <p>All the code above so far cannot be changed in any way in the codebase, I need to work with it. </p>
  
  <hr>
  
  <p><strong>Here starts my problem:</strong></p>
  
  <p>Let's filter the array with media to only image cases</p>
  
  <pre><code>    let imageOnlyCases: [Content] = media.filter { item -&gt; Bool in
  
          switch item {
          case .Image: return true
          default: return false
          }
      }
  </code></pre>
  
  <p>Next step, I want to get from array of enum to an array of their associated values</p>
  
  <pre><code>[Content] -&gt; [ShareableImage] by using map.
  </code></pre>
  
  <p>so I do this</p>
  
  <pre><code>    let shareablemages = imageOnlyCases.map { imageCase -&gt; ShareableImage in
  
          switch imageCase {
  
          case .Image(let image): return image
          default: return  WHAT TO DO HERE?
          }
      }
  </code></pre>
  
  <p>You see, I have a problem with return type..I know that the enum cases are all .Image..and I want a simple map. But the swift syntax is not helping me.</p>
  
  <p>Any ideas?</p>