title: In Swift 3, how do I get UnsafeRawPointer from Data?
body: <p>According to the documentation of Data in Swift 3, there is an initializer that I can use to create a Data from UnsafeRawPointer. What I need actually is the opposite. I have a Data, and I want to create a UnsafeRawPointer that points to the bytes of the Data. Here's what I'm doing right now:</p>
  
  <pre><code>1. let data = &lt;from some where&gt;
  2. let unsafePointer = UnsafeMutablePointer&lt;UInt8&gt;.allocate(capacity: data.count)
  3. unsafePointer.initialize(to: 0, count: data.count) // is this necessary?
  4. data.copyBytes(to: unsafePointer, count: data.count)
  5. let unsafeRawPointer = unsafePointer.deinitialize() // this is of the type UnsafeMutalbleRawPointer, and I can use it where UnsafeRawPointer is needed.
  </code></pre>
  
  <p>I verified that this code works in Xcode Playground. The code even works without the line number 3. I'm not sure what is the difference with or without the line. Anyway, my question is, am I doing right for what I want? Is there a simpler way to do it?</p>