title: How to convert from array of UInt8 to Data?
body: <p>There are many questions asking about <a href="https://stackoverflow.com/questions/40535774/swift-3-0-convert-data-to-arrayuint8/40550166">converting <code>Data</code> to an <code>\[UInt8\]</code></a>. I would like to do the opposite. Convert from <code>[UInt8]</code> to <code>Data</code>.</p>
  
  <p>I looked at the initializers, and these seem to be the most promising:</p>
  
  <ol>
  <li><code>init(elements: Sequence)</code></li>
  <li><code>init(bytes: UnsafeRawPointer, count: Int)</code> </li>
  <li><code>init(repeating: UInt8, count: Int)</code></li>
  </ol>
  
  <p>The problem with #1, is that it takes in any sequence, not just <code>[UInt8]</code>. Therefore, it doesn't give me much confidence that it'll encode my data exactly as I want.</p>
  
  <p>The problem with #2, is that I'm not sure how to convert from <code>[UInt8]</code> to <code>UnsafeRawPointer</code>. Also the unsafe part makes me think this is not the correct approach.</p>
  
  <p>The problem with #3, is that it only allows me to repeat the same exact byte, multiple times. My data contains different bytes.</p>
  
  <p>How do I convert from <code>[UInt8]</code> to <code>Data</code>?</p>