title: Swift - How do you cast a CVImageBufferRef as a CVPixelBufferRef
body: <p>In objective-c you can easily cast a CVImageBufferRef as a CVPixelBufferRef:</p>
  
  <pre><code>CMSampleBufferRef sampleBuffer = some value
  
  CVPixelBufferRef pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
  </code></pre>
  
  <p>How can I do this in swift?</p>
  
  <hr>
  
  <pre><code>var pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer)
  </code></pre>
  
  <p>gives the error: 'Unmanaged&lt;CVPixelBufferRef&gt;' is not convertible to 'CVPixelBufferRef'</p>
  
  <hr>
  
  <pre><code>var pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer).takeRetainedValue()
  </code></pre>
  
  <p>gives the error: 'CVImageBuffer' is not convertible to 'CVPixelBufferRef'</p>
  
  <hr>
  
  <pre><code>var pixelBuffer : CVPixelBufferRef = CMSampleBufferGetImageBuffer(sampleBuffer).takeRetainedValue() as CVPixelBufferRef
  </code></pre>
  
  <p>gives the error: Cannot convert the expression's type 'CVPixelBufferRef' to type 'CVPixelBufferRef'</p>